Refactored so parse tree is less stateful; helps with undo