performance improvement for Gen.frequency

 (using a TreeMap for faster lookup instead of repeated linear scanning), including LONGer tot.