More cleanup and refactoring.