Some improvements to tree building added