Continuing refactoring.
More refactoring, fixes.