Fixed tree generation bugs