Refactored merge()