Move `expandTree` utility function into the models initializator.