cleaning up and extending tree processing