error handling and logging fixes