Backported changes from 3.0 branch