Removed unnecessary casts + various fixes.