Optimize merge sort