implemented brute force grouping