Some fixes to nearestneigbors and fix in granularit