Refactored tree rebuild into an action