refactored tree.js