Fix potential undefined index error