some optimization for computeOrderedGroups