BUG: FIX for #5430

There's a failing test case and the patch in subsequent commits.