backport important fixes to 1.8