Wrote knnsearch function