Merge function