Back port the changes from d8269c7cb85c7d78a29c5aa9c9acc03a266684f1