fixed a state toggle bug