Implement mergeNodes