clean up for the merge function