Formalizing Stateful Behavior Trees