Added method buildTree