refactor merge sort