change error funct to avoid inf