Fix edge case bug at end of top-level fold