Removed sqrt from knn distance function, fixed indexing