backports missing logic and tests from 7 that I overlooked.