Refactor BEMTREE