Refactored Merge code.