Updated folding for sections

Improved handling of which parts to fold and which parts not to fold, and which
parts should be folded at the same level.