Port patch from master
Port patch from master