Commit state files atomically with rename

Closes GH-176