make sure d_avg is never zero