Backport fixes from old version