Modified the storage service to write the state to a temporary file which is moved to the proper location when the write is complete.