Fix undefined indexes