More refactorings and code/test organization.