refactored tree funcs to use a new fold fn