refactored Tree.js