Running a song beat by beat -> Buzzer and LED stuck on first beat condition.

Essentially, I am playing a song by buzzing a buzzer and flashing an LED at the same time. The code has been long and complicated but I wanted to know if anything looks incorrect with this section of it. It seems to give me the most problems.

for (beatloop = 1; beatloop < numbeats + 1; beatloop = beatloop + 1)
// I know the number of total beats in the song. I am taking the song beat by beat. //

{
if ((beatloop % 4 == 1) || (beatloop % 4 == 2))
{
lightLevel = 1023;
pinMode(ledPin, OUTPUT);
analogWrite(ledPin,lightLevel);
}
if ((beatloop % 4 == 3) || (beatloop % 4 == 0))
{
lightLevel = 0;
pinMode(ledPin, OUTPUT);
analogWrite(ledPin,lightLevel);
}
// Alternating the light on and off, splitting up cases based on remainders. //

divider2 = melody[currenttone+1];
// Melody is the song array, divider2 is reading the note lengths which are stored every second value. I start currenttone @ 0. //

if (divider2 < 0)
{
divider2 = abs(divider2) * 2/3;
}
// Conversion of some numbers in this table

if (beatcounter == 0)
{
beatcounter = (8/divider2);
}
beatcounter = beatcounter - 1;
// # of beats is 8/divider2. The beat counter starts at that value and goes down 1 beat at a time, unless its at zero in which case the next note is loaded.

tone(buzzer, melody[currenttone], 500);
// Play the buzzer, play the note (frequency), play it a length

if (beatcounter == 0)
{
currenttone = currenttone + 2;
}

// The next note is loaded when every the beancounter expires. //

I have been working for a number of hours to try to solve this. Thanks to anyone who can assist.

It seems to give me the most problems.

Such as ?

The problem I am currently having is that I am stuck on a single buzzer note and the ledPin appears to be continuously on.

I figured out the solution. I switched up the code a little bit, but this is the part that made it function. I have to add the following
->

tone(buzzer, melody[currenttone], 500); // This was already there //
delay (eighthnote);
noTone(buzzer);'

I am a little confused by this solution. Why must the buzzer be switched to noTone before a new one can be written?