"merge" function