made a merging function as preparation for junctions