fixed a bug when changing the state often