Refactor merge_sort