refactoring for graph