Fixes atomic file handling (revert on fail)