More refactoring, still working.