Some exception handling and logging improvements