Back port the changes from 0c72ed00864fbfeada410b6ecb57f143e2f515fa