Various combined fixes

There was a merge conflict with one of my previous PRs. This combines them all into a clean PR that should apply to your master branch.