Replaced heapsort with mergesort