Fixing conversion errors when casting