Improve merge algorithm.