Proper index checking to avoid strict warnings