new grouping logic