mergesort optimization