better grouping algorithm