LPS-47774 Extract tree code into modules