Fix some class cast exceptions.