fixed bug for array out of bound check.