refactor graph.py