Refactor set_state and state methods to go through set_state_ and state_
to simplify implementation of standalone codegen