Overhauled saving document state.