refactored group generation to use mapReduce