slight refactoring and polishing
*tracking down bug in tree building