code for tree layout