encapsulate more in graph.py