Added tests for trees.
Improve detection of shared list in tree.