maybe set it like:

    avg = 0.0;

    if (avg > 0.25) {
        avg = 1.0;
    }