build tree in advance, then use it whenever necessary