Refactoring code for graph.py
Updated the README