supporting both knn>0 and knn<=0