updated NN functions so that they return the distances as well as the indices