Fixed some cross-platform typecasting issues