fixed bug in state switch, added things