upgraded error handling