Fix index not being reset to previous position on error.