Sorting of groups