Add some comments and remove unnecessary casts.