refactor tree logic to service