Added some more rigorous typecasting to satisfy 4.27