Fix merge function