fixed array index bug