use group to perform merge sort