Clean up a bunch of stuff.

Now the code doesn't have to keep passing around program
instances. Other than that, I removed a lot of trailing whitespace
and fixed some bugs.