merge function complete