fixes issues with saving and restoring state