backport several small fixes