test transactional file write, refactor