refactoring graph.java