some corrections to error handling