better TestNeighbors implementation