replace more usage of TreeMap with FlatMap