More cleanup and refactoring for clarity.