use foldr to create initial tree