Fixing bugs in tree build