Add merge function and test