better merging procedure