Fix bad type casting