first version of nearestInsert