added state saving