extract tree code to /libs/tree.js