a bit more concise using isNodeVisited and setNodeVisited methods