backport some fixes