compressed the merge algorithm