tree added. did some refactoring.