Fixed some Class checks that would have caused ClassCastExceptions.