Large refactor. Tree solution working.