Implementation of findNearest().