optimized to avoid multiple expands and collapses