Generic atomic update code

Couldn't resist doing a little cleanup before writing a test.
check & log err: good idea.

But I'm not dropping the original error. Moved the return to make it more clear.