A lot of fixes to logging in error situations