Refactored the Graph class and added new methods