Dozens of random fixes and changes

Some of these came around from testing in a
Windows VM recently.