Optimized version of KNN. Much faster than before.