added getTree helper function