Undefined index fixes

Tidying and repairing undefined indexes.