simplify grouping by using map