Fix class cast to use correct type