starting rewriting of treemode