Various fixes

Let me know if you prefer these broken into separate pull requests.