changed merge function.