Added unittests for the merge func.
Fixed the merge func.