Cherry-picked latest improvements from master.

Included: 83a913f ; 50a5494 ; bceebdf