More refactoring, minor cleanup.