Refactored tree code, and made text html work