Generic atomic update code

Couldn't resist doing a little cleanup before writing a test.
Also, you dropped the return err from here.