fixed wrong index clearing