Add ability to write state to file