Clean up quite a bit of stuff. This shouldn't change actual program logic at all.