better row merging when rows are sorted