abstraction for Graph
refactoring for abstraction