Refactored the graph classes to make their structure more clear.