Logging improvements, hooks, and refactoring.