folding subtrees