refactored merge