ts tree refactored