More refactoring, now just the unit tests fail (which is good I guess).