Implementation of merge sort