All sorts of cleanup and refactoring.