Saving state. Closes #307.