Refactored; added recursive tree parsing