Fixed merge function.