Improved logic of Graph::hasNode()