fix merge function