Fix and simplify expand/collapse behavior, add test.