Refactored Graph::connectNodes()