A whole bunch of refactoring.