New error handling logic