refactored grouping functions - fixed randomNPair option