functional build tree