Improve handling of order when merging.