whole bunch of refactoring