Fix k-nearest neighbour performance