refactored new group-merge fn