More refactoring.

More refactoring, still not done.