Back port the changes from 0ed907b7e297b376a28a1057b7cd0639a92e93f3