Use logging system instead of sys.out
Refactoring & misc changes
Fixed tree message counts