Merge sort refactoring