fix undefinied index error