Fix invalid array access which caused crash