(manual) backport of 1.7's master_state changes
Merge pull request #254 from Incubaid/master_state_1.6

(manual) backport of 1.7's master_state changes