Improvements and fixes to logging