Fix ClassCastExceptions