smarter error handling