Refactoring

Cleaning up a few ugly bits of the code base.