[IM] More rebust checking of array indices