cherry-pick a few upstream patches