kindTree, defined functions + logic of tree function