More refactoring and cleanup.