Implementation of merge sort.