Improve handling of collapse/expand.  Fixes #2036

Change-Id: I05979576d8d4066321b41a22c1598664b975dc02