Clean-ups

Miscellaneous clean-ups of code all over the place.

When I've been fixing definite bugs, or reading code to make sense of a bug I'm investigating, I tend to tidy up the code, if only to make it easier to see what it's doing.  I've been stashing those changes, once I know how to fix the bug, and saving them on this branch.  It's quite long now.