more sophisticated error handling