Fix undefined index handling

Until now, the code caused several "PHP Notice:  Undefined index:".