better tree code