Fix undefined index errors