some fixes in state logic