implemented creation of subgraph when merging nodes