Complete mergesort implementation