expand-collapse, minor optimizations