fix some error handling cases