Tree helper refactoring