Transactional file changes update.

This is a copy of #166 with my own patches applied on top of it.

To see changes between #166 and this without the diff being cluttered by a file rename:

`git diff 2cab336..fcc75a8`