Minor code improvements, started to work on keeping the expanded state
during updateTree.