Whole bunch of refactoring.