refactored expand/collapse