Cherrypicked from commit 7474a0dc3cc12f3770e367c3624380392d794cb7