Fixed invalid index error