Cleaned up code (again).

I'm still working on cleaning things up, but some of the organization is
done.