Error handling and logging