diff --git a/src/commands/settings/rolemenu.ts b/src/commands/settings/rolemenu.ts
index 7da9dfe..0b41854 100644
--- a/src/commands/settings/rolemenu.ts
+++ b/src/commands/settings/rolemenu.ts
@@ -120,6 +120,7 @@
                     .setStyle(TextInputStyle.Short)
                     .setValue(name ?? "")
                     .setRequired(true)
+                    .setMaxLength(100)
             ),
             new ActionRowBuilder<TextInputBuilder>().addComponents(
                 new TextInputBuilder()
@@ -128,6 +129,8 @@
                     .setPlaceholder("A short description of the role (e.g. A role for people who code)")
                     .setStyle(TextInputStyle.Short)
                     .setValue(description ?? "")
+                    .setRequired(false)
+                    .setMaxLength(100)
             )
         );
     const button = new ActionRowBuilder<ButtonBuilder>().addComponents(
@@ -159,15 +162,15 @@
     if (!out) return [name, description];
     if (out.isButton()) return [name, description];
     name = out.fields.fields.find((f) => f.customId === "name")?.value ?? name;
-    description = out.fields.fields.find((f) => f.customId === "description")?.value ?? description;
+    description = out.fields.fields.find((f) => f.customId === "description")?.value ?? "";
     return [name, description];
 };
 
 const defaultRoleMenuData = {
-    name: "Role Menu Page",
-    description: "A new role menu page",
+    name: "New Page",
+    description: "",
     min: 0,
-    max: 0,
+    max: 1,
     options: []
 };
 
@@ -196,17 +199,20 @@
     );
 
     let back = false;
-    if (data.options.length === 0) {
-        data.options = [{ name: "Role 1", description: null, role: "No role set" }];
-    }
     do {
-        const previewSelect = configToDropdown("Edit Roles", {
-            name: data.name,
-            description: data.description,
-            min: 1,
-            max: 1,
-            options: data.options
-        });
+        const noRoles = data.options.length === 0;
+        const previewSelect = configToDropdown(
+            "Edit Roles",
+            {
+                name: data.name,
+                description: data.description,
+                min: 1,
+                max: 1,
+                options: noRoles ? [{ name: "Role 1", description: null, role: "No role set" }] : data.options
+            },
+            undefined,
+            noRoles
+        );
         const embed = new EmojiEmbed()
             .setTitle(`${data.name}`)
             .setStatus("Success")
@@ -215,7 +221,8 @@
                     `**Min:** ${data.min}` +
                     (data.min === 0 ? " (Members will be given a skip button)" : "") +
                     "\n" +
-                    `**Max:** ${data.max}\n`
+                    `**Max:** ${data.max}\n` +
+                    `\n**Roles:** ${data.options.length === 0 ? "*No roles set*" : data.options.length}`
             );
 
         await interaction.editReply({ embeds: [embed], components: [previewSelect, buttons] });
@@ -237,7 +244,8 @@
                 await createRoleMenuOptionPage(
                     interaction,
                     m,
-                    data.options.find((o) => o.role === (i as StringSelectMenuInteraction).values[0])
+                    data.options.find((o) => o.role === (i as StringSelectMenuInteraction).values[0]),
+                    false
                 );
             }
         } else if (i.isButton()) {
@@ -255,7 +263,8 @@
                 }
                 case "addRole": {
                     await i.deferUpdate();
-                    data.options.push(await createRoleMenuOptionPage(interaction, m));
+                    const out = await createRoleMenuOptionPage(interaction, m, undefined, true);
+                    if (out) data.options.push(out);
                     break;
                 }
             }
@@ -268,8 +277,10 @@
 const createRoleMenuOptionPage = async (
     interaction: StringSelectMenuInteraction | ButtonInteraction,
     m: Message,
-    data?: { name: string; description: string | null; role: string }
+    data?: { name: string; description: string | null; role: string },
+    newRole: boolean = false
 ) => {
+    const initialData = _.cloneDeep(data);
     const { renderRole } = client.logger;
     if (!data)
         data = {
@@ -281,19 +292,29 @@
     const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents(
         new ButtonBuilder()
             .setCustomId("back")
-            .setLabel("Back")
-            .setStyle(ButtonStyle.Secondary)
-            .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji),
+            .setLabel(newRole ? "Add" : "Back")
+            .setStyle(newRole ? ButtonStyle.Success : ButtonStyle.Secondary)
+            .setEmoji(getEmojiByName("ICONS.SAVE", "id") as APIMessageComponentEmoji),
         new ButtonBuilder()
             .setCustomId("edit")
             .setLabel("Edit Details")
             .setStyle(ButtonStyle.Primary)
-            .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji)
+            .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji),
+        new ButtonBuilder()
+            .setCustomId("delete")
+            .setLabel("Delete")
+            .setStyle(ButtonStyle.Danger)
+            .setEmoji(getEmojiByName("TICKETS.ISSUE", "id") as APIMessageComponentEmoji),
+        new ButtonBuilder()
+            .setCustomId("cancel")
+            .setLabel("Cancel")
+            .setStyle(ButtonStyle.Secondary)
+            .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji)
     );
     do {
         const roleSelect = new RoleSelectMenuBuilder()
             .setCustomId("role")
-            .setPlaceholder(data.role ? "Set role to" : "Set the role");
+            .setPlaceholder(data.role ? "Change role to" : "Select a role");
         const embed = new EmojiEmbed()
             .setTitle(`${data.name}`)
             .setStatus("Success")
@@ -325,6 +346,12 @@
             if (i.customId === "role") {
                 await i.deferUpdate();
                 data.role = (i as RoleSelectMenuInteraction).values[0]!;
+                await interaction.editReply({
+                    embeds: [
+                        new EmojiEmbed().setTitle(`Applying changes`).setStatus("Danger").setEmoji("NUCLEUS.LOADING")
+                    ],
+                    components: []
+                });
             }
         } else if (i.isButton()) {
             switch (i.customId) {
@@ -334,7 +361,6 @@
                     break;
                 }
                 case "edit": {
-                    await i.deferUpdate();
                     const [name, description] = await editNameDescription(
                         i,
                         interaction,
@@ -345,6 +371,15 @@
                     data.description = description ? description : data.description;
                     break;
                 }
+                case "delete": {
+                    await i.deferUpdate();
+                    return null;
+                }
+                case "cancel": {
+                    await i.deferUpdate();
+                    if (newRole) return null;
+                    else return initialData;
+                }
             }
         }
     } while (!back);
@@ -383,6 +418,7 @@
                     .setValue("delete")
                     .setEmoji(getEmojiByName("TICKETS.ISSUE", "id") as APIMessageComponentEmoji)
             );
+        console.log(page);
         const buttonRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
             new ButtonBuilder()
                 .setCustomId("back")
@@ -422,7 +458,7 @@
             actionSelect.setDisabled(true);
             pageSelect.addOptions(new StringSelectMenuOptionBuilder().setLabel("No role menu pages").setValue("none"));
         } else {
-            page = Math.min(page, Object.keys(currentObject).length - 1);
+            page = Math.max(Math.min(page, currentObject.length - 1), 0);
             current = currentObject[page]!;
             embed.setDescription(
                 `**Currently Editing:** ${current.name}\n\n` +
