Debug and optimize following code. After giving out the complete optimized code create a short overview table of what you have changed and why. import tkinter as tk
from tkinter import ttk, filedialog, messagebox
import json
import os


class MRTHandbuch(tk.Tk):
    def init(self):
        super().init()

        self.title(“MRT Sequenzen Handbuch”)
        self.geometry(“800x600”)

        self.protocol(“WM_DELETE_WINDOW”, self.on_exit)

        self.sequenzen = [“T1”, “T2”, “PD”, “DWI”, “SWI”, “T2 FLAIR”, “Freie Eingabe”]
        self.ausrichtungen = [“transversal”, “sagittal”, “coronal”, “Freie Eingabe”]

        self.init_ui()

    def init_ui(self):
        self.create_widgets()
        self.load_protokolle()

    def create_widgets(self):
        self.left_frame = tk.Frame(self)
        self.left_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)

        self.right_frame = tk.Frame(self)
        self.right_frame.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)

        # Liste der Protokolle
        self.protokoll_listbox = tk.Listbox(self.right_frame)
        self.protokoll_listbox.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
        self.protokoll_listbox.bind(“<<ListboxSelect>>”, self.load_protokoll_details)

        # Button zum Hinzufügen der Sequenz
        self.sequenz_button = tk.Button(self.right_frame, text=“Sequenz hinzufügen”, command=self.add_sequenz)
        self.sequenz_button.pack(side=tk.TOP, pady=5)

        # Button zum Speichern des Protokolls
        self.save_button = tk.Button(self.right_frame, text=“Protokoll speichern”, command=self.save_protokoll)
        self.save_button.pack(side=tk.TOP, pady=5)

    def add_sequenz(self):
        sequenz_frame = tk.Frame(self.left_frame, borderwidth=1, relief=“solid”)
        sequenz_frame.pack(side=tk.TOP, fill=tk.X, pady=5)

        ttk.Label(sequenz_frame, text=“Sequenz:”).grid(row=0, column=0, padx=5, pady=5)
        sequenz_combo = ttk.Combobox(sequenz_frame, values=self.sequenzen)
        sequenz_combo.grid(row=0, column=1, padx=5, pady=5)

        ttk.Label(sequenz_frame, text=“Ausrichtung:”).grid(row=0, column=2, padx=5, pady=5)
        ausrichtung_combo = ttk.Combobox(sequenz_frame, values=self.ausrichtungen)
        ausrichtung_combo.grid(row=0, column=3, padx=5, pady=5)

        ttk.Label(sequenz_frame, text=“Anmerkung:”).grid(row=1, column=0, padx=5, pady=5)
        anmerkung_entry = ttk.Entry(sequenz_frame)
        anmerkung_entry.grid(row=1, column=1, columnspan=3, padx=5, pady=5, sticky=tk.W+tk.E)

    def load_protokolle(self):
        self.protokoll_listbox.delete(0, tk.END)

        if os.path.exists(“protokolle.json”):
            with open(“protokolle.json”, “r”) as file:
                self.protokolle_data = json.load(file)
            for protokoll_name in self.protokolle_data:
                self.protokoll_listbox.insert(tk.END, protokoll_name)

    def save_protokoll(self):
        protokoll_name = filedialog.asksaveasfilename(defaultextension=“.json”)
        if protokoll_name:
            sequenzen = []
            for sequenz_frame in self.left_frame.winfo_children():
                sequenz_data = {
                    “sequenz”: sequenz_frame.winfo_children()[1].get(),
                    “ausrichtung”: sequenz_frame.winfo_children()[3].get(),
                    “anmerkung”: sequenz_frame.winfo_children()[5].get()
                }
                sequenzen.append(sequenz_data)

            self.protokolle_data[protokoll_name] = sequenzen

            with open(“protokolle.json”, “w”) as file:
                json.dump(self.protokolle_data, file)

            self.load_protokolle()

    def load_protokoll_details(self, event):
        selected_protokoll = self.protokoll_listbox.get(self.protokoll_listbox.curselection())

        for child in self.left_frame.winfo_children():
            child.destroy()

        for sequenz_data in self.protokolle_data[selected_protokoll]:
            self.add_sequenz()
            sequenz_frame = self.left_frame.winfo_children()[-1]
            sequenz_frame.winfo_children()[1].set(sequenz_data[“sequenz”])
            sequenz_frame.winfo_children()[3].set(sequenz_data[“ausrichtung”])
            sequenz_frame.winfo_children()[5].delete(0, tk.END)
            sequenz_frame.winfo_children()[5].insert(tk.END, sequenz_data[“anmerkung”])

    def on_exit(self):
        if messagebox.askyesno(“Beenden”, “Möchten Sie das Programm wirklich beenden?”):
            self.destroy()


if name == “main”:
    handbuch = MRTHandbuch()
    handbuch.mainloop()