More cleaning up, and refactoring