Simplified merge sort into one function