add bad index check.