Generic atomic update code

Couldn't resist doing a little cleanup before writing a test.