fixes for nearestneighbor