Smarter error handling