first function for subgraph