basic tree code