Fix merge sort memory usage