backport fixes from master