Working around ClassCastException with SortedSet.