Typecasting bug fixes