Does currentWave() ever change within this function? You're calling it a LOT.