Fix to KNN function