rewrite code, rename to merge2