[TASK] Clean up tree code