fixed KNN out of range issue