refactoring knn