encapsulated the grouping logic, lots of cleanup