fixed a crash caused by invalid state changing