fixed a little bug: after empty the array I have to reinitialize the currentIndex

fixed a little bug: after empty the array I have to reinitialize the currentIndex