fix bugs for state behavior