Implemented inplace merging.