error handling bug fix