Remove the unnessary line, because the callback mechanism calls resetIndex() in it.
Add error checks.