modify the knn search code