backports missing logic and tests from 7 that I overlooked.
Merge remote-tracking branch 'origin/6.2.0' into 7.0.2