Bit of cleanup

Cleaned up a bit. Code still needs a major restructuring into separate
classes/files/whatever. I'll need to think about this.