fixed the state change bug