Added some casts. Removed an unneeded debug line