fixed nullptr check to addNeighbor method