Backport fixes from next

These are some fixes that should be backported to master for the next release,
IMO.

All patches here have been reviewed and merged to next.