def modify_val(val, modify_by=0.0, should_modify=True, upper_lim=1, lower_lim=0
    ):
    """Modify a value and check its range."""
    if should_modify:
        val = val + modify_by
    if val > upper_lim:
        return upper_lim
    elif val < lower_lim:
        return lower_lim
    else:
        return val
