added some state saving