refactor tree to entity