Improving error handling