refactored tree id piece to function