Solved issue with State Machine