add subgraph function