fix nneighbor calculation