Refactoring merge sort outside the list