fixed how states are being saved