Assorted fixes

Fixes from multiple issues, combined because they overlapped and some PRs were changed.