Fixed array index bug