improvements to state_tree, implementation of next_state