Bug Fix: Avoid ClassCastExceptions.