Fixing undefined index errors