Changed variable N to currentIndex