refactored merge related functions