Logging improvements, and some tests