Fixed some errors causing ClassCastExceptions