more replacing TreeMap with FlatMap to fix build