fix access to array element by using the one that was checked for