Updated kNN algorithm