fixed the bug of invalid state