#10 use simpler grouping and sorting algorithm