Added overtone protection by addind a case where max_idx = 1 at the end of the cycle. If this is the case, we picked up an overtone, need to multiply the divider by 2 and not use the new value