Fix isNeighbor function