Minor fixes, and /possibly/ improvements

There are a bunch of unrelated changes here, but I'm hoping you'll cherry pick at least a few out.  If you'd prefer to have some of them in a separate issue or in one squashed commit or whatever, just say.  Make me do the work ;)

If the reasons for any of the changes aren't clear, I'd be happy to explain them more thoroughly.

Thanks,

James