Tweaked tree-walks for performance. Stores results of tree-walks and only rewalks tree when required.