better merge function and test fixes