refactored Graph class