refactor tree.js to use promises