Im reading through your code now, there are a few errors
two things i find useful when writing code are
Serial.println(pwm_count_old[index]); // debug to serial monitor
so you can see whats happening and also
while(1);
when you don't want void loop() to continously repeat, also useful for debugging