Fix k-NN bug