Refactoring Graph class