Reimplement sortGroups method