cherry-picked 6344b44 & fa211ec