code refactoring: the graph is handled by its own class now