Improvement to error handling