Generic tree build and fixing bug