Back port the changes from 6917fff2a0271e6306a6343712b8add70855d8da