Add checks for array indices.