bug fix and wired tree building