Some massive, untested refactoring