merge function