Fix undefined index handling