it is logical to insert new value if "before", then current value, then new value if "after".
Oh, I see now. There is a slightly different logic: `v` is a current value and `newval` is a new value. So basically we insert a current item in case of "after", then a new value (if it's not a delete operation), then a current item in case of "before". But I agree, this code can be more straightforward. I've attached a new version, pls take a look (it contains the same logic that you've mentioned).