Fixed array index comparison issue