Fixing many minor issues

PTAL.

Please review using the whitespace-insensitive flag.

I'll edit this description soon to add links to the bugs that are being fixed.