Even more refactorings and cleanups.