build tree first