Cast to the right type