generalize from TreeMap to SortedMap