optimized mergesort