Finished merging algorithm.