finished neighborsOf function