Improved nearest neighbor algorithm slightly.