Added some casts and comments