Added a null pointer verification in Graph class