Simplify grouping logic