correctly reduce state during recursion

modify "tree" in place