Implementing the merge sort algorithm