added merge function and corresponding tests.