finished foldleft (tree implementation