Cherry-picked changes from master, 43b009f..4020e23