Fixed some issues with state saving