Mergesort implementation