Backport misc. fixes and features