Changes to use TreeMap or TreeSet when searching for an implementation
for SortedMap and SortedSet