implemented loadstate and savestate