The "update row count after insertion" comment is followed by a line that increments i by one.
But you've added a new row that doesn't seem to have a checkbox, and when you increment i by one, that's the new row it points to. It should probably change the increment of i to i = i + 2 in the first case (but leave it i+1 in the "else" case) in order to work properly.