First implementation of nearest().