Move some of "expression_state" into other functions for clarity and a small bugfix