Continued refactorization and cleanup.