cherrypicked from  b95f7