correctly fix `undefined index` problem