Initial implementation of foldTree