Treefy and substitue funcitions