nearest() algo working and tested