fixes to nearest neighbor