Refactored merging