working on nearest detection