Fixed some minor issues in the merging algorithm.