Tree sort problem solved. Refactoring started.