Merge sort optimization