added support for saving state