Fixed possible loop bug caused by unset leaving index gaps.