backport a couple of fixes