clean up tree processing code