Give me feedback to my code. Dont change anything yet, since it works fine.

function sendEmails() {
  const ss = SpreadsheetApp.openById(SPREADSHEET_ID);
  const sheetNames = ['Nicht erreicht', 'Nicht erreicht 02', 'Nicht erreicht 03'];
  const contentSheet = ss.getSheetByName('Email Content');
  
  if (!contentSheet) {
    Logger.log('Email Content sheet not found. Please create a sheet named "Email Content".');
    return;
  }
  
  const contentData = contentSheet.getDataRange().getValues();
  const emailContent = {};
  
  contentData.forEach(row => {
    if (row[0] && row[1]) {
      emailContent[row[0]] = row[1];
      Logger.log(`Extracted email content for label '${row[0]}': ${row[1]}`);
    }
  });
  
  sheetNames.forEach(sheetName => {
    const sheet = ss.getSheetByName(sheetName);
    if (sheet) {
      processSheet(sheet, emailContent);
    }
  });
}

function processSheet(sheet, emailContent) {
  const data = sheet.getDataRange().getValues();
  const headers = data.shift();
  
  const mailSendenIndex = headers.indexOf('Mail senden?');
  const crmStatusIndex = headers.indexOf('CRM Status');
  const emailAddressIndex = headers.indexOf('E-Mail-Adresse');
  const threadIdIndex = headers.indexOf('Thread-ID');
  
  const rowsToDelete = [];
  
  data.forEach((row, index) => {
    const crmStatus = row[crmStatusIndex];
    const shouldSendEmail = row[mailSendenIndex] === 'Ja';
    const recipient = row[emailAddressIndex];
    const threadId = row[threadIdIndex];
    const currentLabel = sheet.getName();
    
    if (shouldSendEmail) {
      sendEmailAndUpdateLabel(recipient, threadId, currentLabel, emailContent);
      rowsToDelete.push(index + 2);
    } 
    else if (crmStatus && !crmStatus.includes('Nicht erreicht')) {
      updateLabelToErfolg(threadId);
      rowsToDelete.push(index + 2);
    } 
  });
  
  for (let i = rowsToDelete.length - 1; i >= 0; i--) {
    sheet.deleteRow(rowsToDelete[i]);
  }
}

function sendEmailAndUpdateLabel(recipient, threadId, currentLabel, emailContent) {
  Logger.log('sendEmailAndUpdateLabel called with parameters:');
  Logger.log('recipient: ' + recipient);
  Logger.log('threadId: ' + threadId);
  Logger.log('currentLabel: ' + currentLabel);
  Logger.log('emailContent: ' + JSON.stringify(emailContent));
  
  const subject = emailContent['Subject'] || 'Re: Follow-up';
  const body = emailContent[currentLabel] || 'This is a follow-up email.';
  
  Logger.log('subject: ' + subject);
  Logger.log('body: ' + body);
  
  const thread = GmailApp.getThreadById(threadId);
  if (!thread) {
    Logger.log('Thread not found: ' + threadId);
    return;
  }
  
  Logger.log('Thread found: ' + threadId);
  
  const messageIds = thread.getMessages().map(function(msg) {
    return msg.getHeader('Message-ID');
  });
  
  Logger.log('messageIds: ' + messageIds);
  
  const rawMessage = createRawMessage(recipient, subject, body, messageIds);
  
  Logger.log('rawMessage: ' + rawMessage);
  
  const message = {
    raw: rawMessage,
    threadId: threadId
  };
  
  Logger.log('message: ' + JSON.stringify(message));
  
  try {
    const url = 'https://gmail.googleapis.com/gmail/v1/users/me/messages/send';
    const options = {
      method: 'post',
      contentType: 'application/json',
      payload: JSON.stringify(message),
      headers: {
        Authorization: 'Bearer ' + ScriptApp.getOAuthToken()
      }
    };
    
    UrlFetchApp.fetch(url, options);
    
    Logger.log('Email sent successfully');
    
    updateLabel(threadId, currentLabel);
    
  } catch (error) {
    Logger.log('Error sending email: ' + error.toString());
  }
}

function updateLabel(threadId, currentLabel) {
  const thread = GmailApp.getThreadById(threadId);
  if (!thread) {
    Logger.log(`Thread with ID '${threadId}' not found.`);
    return;
  }

  // Try to get the old label, but create it if necessary
  let oldLabel = GmailApp.getUserLabelByName(currentLabel);
  if (!oldLabel) {
    Logger.log(`Old label '${currentLabel}' not found, creating it.`);
    oldLabel = GmailApp.createLabel(currentLabel);
  }

  // Log the current labels on the thread
  const currentLabels = thread.getLabels().map(label => label.getName());
  Logger.log(`Current labels on thread ${threadId}: ${currentLabels}`);

  // Remove the old label if it exists
  if (oldLabel) {
    Logger.log(`Attempting to remove old label '${currentLabel}' from thread ${threadId}.`);
    thread.removeLabel(oldLabel);
    Logger.log(`Old label '${currentLabel}' removed.`);
  }

  let newLabelName;

  switch (currentLabel) {
    case 'Nicht erreicht':
      newLabelName = 'Erstkontakt calls/Nicht erreicht/02';
      break;
    case 'Nicht erreicht 02':
      newLabelName = 'Erstkontakt calls/Nicht erreicht/03';
      break;
    case 'Nicht erreicht 03':
      newLabelName = 'Erstkontakt calls/Nicht erreicht/Lost';
      break;
    default:
      Logger.log(`Unrecognized label: ${currentLabel}`);
      return;
  }

  Logger.log(`Transitioning label from '${currentLabel}' to '${newLabelName}'.`);

  // Ensure the new label exists by creating it if necessary
  let newLabel = GmailApp.getUserLabelByName(newLabelName);
  if (!newLabel) {
    Logger.log(`New label '${newLabelName}' not found, creating it.`);
    newLabel = GmailApp.createLabel(newLabelName);
  }

  if (newLabel) {
    Logger.log(`Adding new label: '${newLabelName}' to thread ${threadId}.`);
    thread.addLabel(newLabel);
    Logger.log(`New label '${newLabelName}' added.`);
  } else {
    Logger.log(`Failed to create or retrieve new label: '${newLabelName}'.`);
  }

  // Log the labels after modification
  const updatedLabels = thread.getLabels().map(label => label.getName());
  Logger.log(`Updated labels on thread ${threadId}: ${updatedLabels}`);
  
  // Ensure only the new label remains
  const remainingOldLabels = thread.getLabels().filter(label => label.getName() === currentLabel);
  if (remainingOldLabels.length > 0) {
    Logger.log(`Removing remaining old labels: '${currentLabel}'`);
    remainingOldLabels.forEach(label => thread.removeLabel(label));
    Logger.log(`Remaining old label '${currentLabel}' removed.`);
  }
}

function updateLabelToErfolg(threadId) {
  const thread = GmailApp.getThreadById(threadId);
  const oldLabels = thread.getLabels();
  const erfolgLabel = GmailApp.getUserLabelByName('Erstkontakt calls/Nicht erreicht/Erfolg') || GmailApp.createLabel('Erstkontakt calls/Nicht erreicht/Erfolg');
  
  oldLabels.forEach(label => {
    if (label.getName().startsWith('Erstkontakt calls/Nicht erreicht')) {
      thread.removeLabel(label);
    }
  });
  
  thread.addLabel(erfolgLabel);
}

function createRawMessage(to, subject, body, messageIds) {
  const newMessageId = '<' + Utilities.getUuid() + '@gmail.com>';
  const references = messageIds.join(' ');
  const inReplyTo = messageIds[messageIds.length - 1];
  
  if (messageIds.length > 0 && !subject.toLowerCase().startsWith('re:')) {
    subject = 'Re: ' + subject;
  }

  const rawContent = [
    'To: ' + to,
    'Subject: ' + subject,
    'Message-ID: ' + newMessageId,
    'References: ' + references,
    'In-Reply-To: ' + inReplyTo,
    'Content-Type: text/plain; charset=UTF-8',
    '',
    body
  ].join('\r\n');
  
  return Utilities.base64EncodeWebSafe(rawContent);
}