Fix possible ClassCastException