This is O(n). Maybe just use a flag later in the code and if nmotion has not been found in the usual set of updates, do the update then?