implements mergesort