(manual) backport of 1.7's master_state changes