Added method to generate tree