cherry-picked cf8f25e