Protecting against undefined indexes