diff --git a/src/commands/settings/oldStats.ts b/src/commands/settings/oldStats.ts
new file mode 100644
index 0000000..475b5d3
--- /dev/null
+++ b/src/commands/settings/oldStats.ts
@@ -0,0 +1,291 @@
+import { LoadingEmbed } from "../../utils/defaults.js";
+import Discord, { CommandInteraction, Message, ActionRowBuilder, StringSelectMenuBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuOptionBuilder, APIMessageComponentEmoji, MessageComponentInteraction, TextInputBuilder } from "discord.js";
+import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
+import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import client from "../../utils/client.js";
+import convertCurlyBracketString from "../../utils/convertCurlyBracketString.js";
+import singleNotify from "../../utils/singleNotify.js";
+import getEmojiByName from "../../utils/getEmojiByName.js";
+import createPageIndicator from "../../utils/createPageIndicator.js";
+import { modalInteractionCollector } from "../../utils/dualCollector.js";
+import type { GuildConfig } from "../../utils/database.js";
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+    builder
+        .setName("stats")
+        .setDescription("Controls channels which update when someone joins or leaves the server")
+
+type ChangesType = Record<string, { name?: string; enabled?: boolean; }>
+
+const applyChanges = (baseObject: GuildConfig['stats'], changes: ChangesType): GuildConfig['stats'] => {
+    for (const [id, { name, enabled }] of Object.entries(changes)) {
+        if (!baseObject[id]) baseObject[id] = { name: "", enabled: false};
+        if (name) baseObject[id]!.name = name;
+        if (enabled) baseObject[id]!.enabled = enabled;
+    }
+    return baseObject;
+}
+
+
+const callback = async (interaction: CommandInteraction) => {
+    try{
+    if (!interaction.guild) return;
+    const { renderChannel } = client.logger;
+    let closed = false;
+    let page = 0;
+    const m: Message = await interaction.reply({ embeds: LoadingEmbed, ephemeral: true, fetchReply: true });
+    let changes: ChangesType = {};
+    do {
+        const config = await client.database.guilds.read(interaction.guild.id);
+        const stats = config.stats;
+        let currentID = "";
+        let current: {
+            name: string;
+            enabled: boolean;
+        } = {
+            name: "",
+            enabled: false
+        };
+        let description = "";
+        let pageSelect = new StringSelectMenuBuilder()
+            .setCustomId("page")
+            .setPlaceholder("Select a stats channel to manage")
+            .setDisabled(Object.keys(stats).length === 0)
+            .setMinValues(1)
+            .setMaxValues(1);
+        let actionSelect = new StringSelectMenuBuilder()
+            .setCustomId("action")
+            .setPlaceholder("Perform an action")
+            .setMinValues(1)
+            .setMaxValues(1)
+            .setDisabled(Object.keys(stats).length === 0)
+            .addOptions(
+                new StringSelectMenuOptionBuilder()
+                    .setLabel("Edit")
+                    .setValue("edit")
+                    .setDescription("Edit the name of this stats channel")
+                    .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji),
+                new StringSelectMenuOptionBuilder()
+                    .setLabel("Delete")
+                    .setValue("delete")
+                    .setDescription("Delete this stats channel")
+                    .setEmoji(getEmojiByName("TICKETS.ISSUE", "id") as APIMessageComponentEmoji)
+            );
+        if (Object.keys(stats).length === 0) {
+            description = "You do not have any stats channels set up yet"
+            pageSelect.addOptions(new StringSelectMenuOptionBuilder().setLabel("No stats channels").setValue("none"))
+        } else {
+            currentID = Object.keys(stats)[page]!
+            current = stats[currentID]!;
+            current = applyChanges({ [currentID]: current }, changes)[currentID]!;
+            for (const [id, { name, enabled }] of Object.entries(stats)) {
+                pageSelect.addOptions(
+                    new StringSelectMenuOptionBuilder()
+                        .setLabel(name)
+                        .setValue(id)
+                        .setDescription(`Enabled: ${enabled}`)
+                );
+            }
+            actionSelect.addOptions(new StringSelectMenuOptionBuilder()
+                .setLabel(current.enabled ? "Disable" : "Enable")
+                .setValue("toggleEnabled")
+                .setDescription(`Currently ${current.enabled ? "Enabled" : "Disabled"}, click to ${current.enabled ? "disable" : "enable"} this channel`)
+                .setEmoji(getEmojiByName(current.enabled ? "CONTROL.TICK" : "CONTROL.CROSS", "id") as APIMessageComponentEmoji)
+            );
+            description = `**Currently Editing:** ${renderChannel(currentID)}\n\n` +
+                `${getEmojiByName(current.enabled ? "CONTROL.TICK" : "CONTROL.CROSS")} Currently ${current.enabled ? "Enabled" : "Disabled"}\n` +
+                `**Name:** \`${current.name}\`\n` +
+                `**Preview:** ${await convertCurlyBracketString(current.name, interaction.user.id, interaction.user.username, interaction.guild.name, interaction.guild.members)}`
+        }
+        const row = new ActionRowBuilder<ButtonBuilder>()
+            .addComponents(
+                new ButtonBuilder()
+                    .setCustomId("back")
+                    .setStyle(ButtonStyle.Primary)
+                    .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji)
+                    .setDisabled(page === 0),
+                new ButtonBuilder()
+                    .setCustomId("next")
+                    .setEmoji(getEmojiByName("CONTROL.RIGHT", "id") as APIMessageComponentEmoji)
+                    .setStyle(ButtonStyle.Primary)
+                    .setDisabled(page === Object.keys(stats).length - 1),
+                new ButtonBuilder()
+                    .setCustomId("add")
+                    .setLabel("Create new")
+                    .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id") as APIMessageComponentEmoji)
+                    .setStyle(ButtonStyle.Secondary)
+                    .setDisabled(Object.keys(stats).length >= 24),
+                new ButtonBuilder()
+                    .setCustomId("save")
+                    .setLabel("Save")
+                    .setEmoji(getEmojiByName("ICONS.SAVE", "id") as APIMessageComponentEmoji)
+                    .setStyle(ButtonStyle.Success)
+                    .setDisabled(Object.keys(changes).length === 0),
+            );
+
+        let embed = new EmojiEmbed()
+            .setTitle("Stats Channels")
+            .setDescription(description + "\n\n" + createPageIndicator(Object.keys(stats).length, page))
+            .setEmoji("SETTINGS.STATS.GREEN")
+            .setStatus("Success")
+
+        interaction.editReply({
+            embeds: [embed],
+            components: [
+                new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(pageSelect),
+                new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(actionSelect),
+                row
+            ]
+        });
+        let i: MessageComponentInteraction;
+        try {
+            i = await m.awaitMessageComponent({ filter: (i) => i.user.id === interaction.user.id, time: 30000 });
+        } catch (e) {
+            closed = true;
+            continue;
+        }
+        if (i.isStringSelectMenu()) {
+            switch(i.customId) {
+                case "page":
+                    page = Object.keys(stats).indexOf(i.values[0]!);
+                    i.deferUpdate();
+                    break;
+                case "action":
+                    if(!changes[currentID]) changes[currentID] = {};
+                    switch(i.values[0]!) {
+                        case "edit":
+                            await i.showModal(
+                                new Discord.ModalBuilder()
+                                    .setCustomId("modal")
+                                    .setTitle(`Stats channel name`)
+                                    .addComponents(
+                                        new ActionRowBuilder<TextInputBuilder>().addComponents(
+                                            new TextInputBuilder()
+                                                .setCustomId("ex1")
+                                                .setLabel("Server Info (1/3)")
+                                                .setPlaceholder(
+                                                    `{serverName} - This server's name\n\n` +
+                                                    `These placeholders will be replaced with the server's name, etc..`
+                                                )
+                                                .setMaxLength(1)
+                                                .setRequired(false)
+                                                .setStyle(Discord.TextInputStyle.Paragraph)
+                                        ),
+                                        new ActionRowBuilder<TextInputBuilder>().addComponents(
+                                            new TextInputBuilder()
+                                                .setCustomId("ex2")
+                                                .setLabel("Member Counts (2/3) - {MemberCount:...}")
+                                                .setPlaceholder(
+                                                    `{:all} - Total member count\n` +
+                                                    `{:humans} - Total non-bot users\n` +
+                                                    `{:bots} - Number of bots\n`
+                                                )
+                                                .setMaxLength(1)
+                                                .setRequired(false)
+                                                .setStyle(Discord.TextInputStyle.Paragraph)
+                                        ),
+                                        new ActionRowBuilder<TextInputBuilder>().addComponents(
+                                            new TextInputBuilder()
+                                                .setCustomId("ex3")
+                                                .setLabel("Latest Member (3/3) - {member:...}")
+                                                .setPlaceholder(
+                                                        `{:name} - The members name\n`
+                                                )
+                                                .setMaxLength(1)
+                                                .setRequired(false)
+                                                .setStyle(Discord.TextInputStyle.Paragraph)
+                                        ),
+                                        new ActionRowBuilder<TextInputBuilder>().addComponents(
+                                            new TextInputBuilder()
+                                                .setCustomId("text")
+                                                .setLabel("Channel name input")
+                                                .setMaxLength(1000)
+                                                .setRequired(true)
+                                                .setStyle(Discord.TextInputStyle.Short)
+                                                .setValue(current.name)
+                                        )
+                                    )
+                            );
+                            await interaction.editReply({
+                                embeds: [
+                                    new EmojiEmbed()
+                                        .setTitle("Stats Channel")
+                                        .setDescription("Modal opened. If you can't see it, click back and try again.")
+                                        .setStatus("Success")
+                                        .setEmoji("SETTINGS.STATS.GREEN")
+                                ],
+                                components: [
+                                    new ActionRowBuilder<ButtonBuilder>().addComponents(
+                                        new ButtonBuilder()
+                                            .setLabel("Back")
+                                            .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
+                                            .setStyle(ButtonStyle.Primary)
+                                            .setCustomId("back")
+                                    )
+                                ]
+                            });
+                            let out: Discord.ModalSubmitInteraction | null;
+                            try {
+                                out = await modalInteractionCollector(
+                                    m,
+                                    (m) => m.channel!.id === interaction.channel!.id,
+                                    (_) => true
+                                ) as Discord.ModalSubmitInteraction | null;
+                            } catch (e) {
+                                continue;
+                            }
+                            if (!out) continue
+                            if (!out.fields) continue
+                            if (out.isButton()) continue;
+                            const newString = out.fields.getTextInputValue("text");
+                            if (!newString) continue;
+                            changes[currentID]!.name = newString;
+                            break;
+                        case "delete":
+                            changes[currentID] = {};
+                            i.deferUpdate();
+                            break;
+                        case "toggleEnabled":
+                            changes[currentID]!.enabled = !stats[currentID]!.enabled;
+                            i.deferUpdate();
+                            break;
+                    }
+                    break;
+            }
+        } else if (i.isButton()) {
+            i.deferUpdate();
+            switch(i.customId) {
+                case "back":
+                    page--;
+                    break;
+                case "next":
+                    page++;
+                    break;
+                case "add":
+                    break;
+                case "save":
+                    let changed = applyChanges(config.stats, changes);
+                    singleNotify("statsChannelDeleted", interaction.guild.id, true)
+                    config.stats = changed;
+                    changes = {}
+                    await client.database.guilds.write(interaction.guildId!, config);
+            }
+        }
+        console.log(changes, config.stats);
+    } while (!closed);
+    } catch(e) {
+        console.log(e)
+    }
+};
+
+const check = (interaction: CommandInteraction) => {
+    const member = interaction.member as Discord.GuildMember;
+    if (!member.permissions.has("ManageChannels"))
+        return "You must have the *Manage Channels* permission to use this command";
+    return true;
+};
+
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file
diff --git a/src/commands/settings/stats.ts b/src/commands/settings/stats.ts
index bd63cdc..118afc2 100644
--- a/src/commands/settings/stats.ts
+++ b/src/commands/settings/stats.ts
@@ -1,5 +1,5 @@
 import { LoadingEmbed } from "../../utils/defaults.js";
-import Discord, { CommandInteraction, Message, ActionRowBuilder, StringSelectMenuBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuOptionBuilder, APIMessageComponentEmoji, MessageComponentInteraction, TextInputBuilder } from "discord.js";
+import Discord, { CommandInteraction, Message, ActionRowBuilder, StringSelectMenuBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuOptionBuilder, APIMessageComponentEmoji, TextInputBuilder, StringSelectMenuInteraction, ButtonInteraction } from "discord.js";
 import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
 import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
 import client from "../../utils/client.js";
@@ -8,205 +8,189 @@
 import getEmojiByName from "../../utils/getEmojiByName.js";
 import createPageIndicator from "../../utils/createPageIndicator.js";
 import { modalInteractionCollector } from "../../utils/dualCollector.js";
-import type { GuildConfig } from "../../utils/database.js";
+
 
 const command = (builder: SlashCommandSubcommandBuilder) =>
     builder
         .setName("stats")
         .setDescription("Controls channels which update when someone joins or leaves the server")
 
-type ChangesType = Record<string, { name?: string; enabled?: boolean; }>
 
-const applyChanges = (baseObject: GuildConfig['stats'], changes: ChangesType): GuildConfig['stats'] => {
-    for (const [id, { name, enabled }] of Object.entries(changes)) {
-        if (!baseObject[id]) baseObject[id] = { name: "", enabled: false};
-        if (name) baseObject[id]!.name = name;
-        if (enabled) baseObject[id]!.enabled = enabled;
-    }
-    return baseObject;
+const showModal = async (interaction: StringSelectMenuInteraction, current: { enabled: boolean; name: string; }) => {
+    await interaction.showModal(
+        new Discord.ModalBuilder()
+            .setCustomId("modal")
+            .setTitle(`Stats channel name`)
+            .addComponents(
+                new ActionRowBuilder<TextInputBuilder>().addComponents(
+                    new TextInputBuilder()
+                        .setCustomId("ex1")
+                        .setLabel("Server Info (1/3)")
+                        .setPlaceholder(
+                            `{serverName} - This server's name\n\n` +
+                            `These placeholders will be replaced with the server's name, etc..`
+                        )
+                        .setMaxLength(1)
+                        .setRequired(false)
+                        .setStyle(Discord.TextInputStyle.Paragraph)
+                ),
+                new ActionRowBuilder<TextInputBuilder>().addComponents(
+                    new TextInputBuilder()
+                        .setCustomId("ex2")
+                        .setLabel("Member Counts (2/3) - {MemberCount:...}")
+                        .setPlaceholder(
+                            `{:all} - Total member count\n` +
+                            `{:humans} - Total non-bot users\n` +
+                            `{:bots} - Number of bots\n`
+                        )
+                        .setMaxLength(1)
+                        .setRequired(false)
+                        .setStyle(Discord.TextInputStyle.Paragraph)
+                ),
+                new ActionRowBuilder<TextInputBuilder>().addComponents(
+                    new TextInputBuilder()
+                        .setCustomId("ex3")
+                        .setLabel("Latest Member (3/3) - {member:...}")
+                        .setPlaceholder(
+                                `{:name} - The members name\n`
+                        )
+                        .setMaxLength(1)
+                        .setRequired(false)
+                        .setStyle(Discord.TextInputStyle.Paragraph)
+                ),
+                new ActionRowBuilder<TextInputBuilder>().addComponents(
+                    new TextInputBuilder()
+                        .setCustomId("text")
+                        .setLabel("Channel name input")
+                        .setMaxLength(1000)
+                        .setRequired(true)
+                        .setStyle(Discord.TextInputStyle.Short)
+                        .setValue(current.name)
+                )
+            )
+    );
 }
 
-
 const callback = async (interaction: CommandInteraction) => {
-    try{
     if (!interaction.guild) return;
     const { renderChannel } = client.logger;
-    let closed = false;
-    let page = 0;
     const m: Message = await interaction.reply({ embeds: LoadingEmbed, ephemeral: true, fetchReply: true });
-    let changes: ChangesType = {};
+    let page = 0;
+    let closed = false;
+    const config = await client.database.guilds.read(interaction.guild.id);
+    const currentObject = config.stats;
+    let modified = false;
     do {
-        const config = await client.database.guilds.read(interaction.guild.id);
-        const stats = config.stats;
-        let currentID = "";
-        let current: {
-            name: string;
-            enabled: boolean;
-        } = {
-            name: "",
-            enabled: false
-        };
-        let description = "";
-        let pageSelect = new StringSelectMenuBuilder()
+        let embed = new EmojiEmbed()
+            .setTitle("Stats Settings")
+            .setEmoji("SETTINGS.STATS.GREEN")
+            .setStatus("Success");
+        const noStatsChannels = Object.keys(currentObject).length === 0;
+        let current: { enabled: boolean; name: string; };
+
+        const pageSelect = new StringSelectMenuBuilder()
             .setCustomId("page")
-            .setPlaceholder("Select a stats channel to manage")
-            .setDisabled(Object.keys(stats).length === 0)
-            .setMinValues(1)
-            .setMaxValues(1);
-        let actionSelect = new StringSelectMenuBuilder()
+            .setPlaceholder("Select a stats channel to manage");
+        const actionSelect = new StringSelectMenuBuilder()
             .setCustomId("action")
             .setPlaceholder("Perform an action")
-            .setMinValues(1)
-            .setMaxValues(1)
-            .setDisabled(Object.keys(stats).length === 0)
             .addOptions(
                 new StringSelectMenuOptionBuilder()
                     .setLabel("Edit")
+                    .setDescription("Edit the stats channel")
                     .setValue("edit")
-                    .setDescription("Edit the name of this stats channel")
                     .setEmoji(getEmojiByName("ICONS.EDIT", "id") as APIMessageComponentEmoji),
                 new StringSelectMenuOptionBuilder()
                     .setLabel("Delete")
+                    .setDescription("Delete the stats channel")
                     .setValue("delete")
-                    .setDescription("Delete this stats channel")
                     .setEmoji(getEmojiByName("TICKETS.ISSUE", "id") as APIMessageComponentEmoji)
+        );
+        const buttonRow = new ActionRowBuilder<ButtonBuilder>()
+                .addComponents(
+                    new ButtonBuilder()
+                        .setCustomId("back")
+                        .setStyle(ButtonStyle.Primary)
+                        .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji)
+                        .setDisabled(page === 0),
+                    new ButtonBuilder()
+                        .setCustomId("next")
+                        .setEmoji(getEmojiByName("CONTROL.RIGHT", "id") as APIMessageComponentEmoji)
+                        .setStyle(ButtonStyle.Primary)
+                        .setDisabled(page === Object.keys(currentObject).length - 1),
+                    new ButtonBuilder()
+                        .setCustomId("add")
+                        .setLabel("Create new")
+                        .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id") as APIMessageComponentEmoji)
+                        .setStyle(ButtonStyle.Secondary)
+                        .setDisabled(Object.keys(currentObject).length >= 24),
+                    new ButtonBuilder()
+                        .setCustomId("save")
+                        .setLabel("Save")
+                        .setEmoji(getEmojiByName("ICONS.SAVE", "id") as APIMessageComponentEmoji)
+                        .setStyle(ButtonStyle.Success)
+                        .setDisabled(modified),
             );
-        if (Object.keys(stats).length === 0) {
-            description = "You do not have any stats channels set up yet"
-            pageSelect.addOptions(new StringSelectMenuOptionBuilder().setLabel("No stats channels").setValue("none"))
+        if (noStatsChannels) {
+            embed.setDescription("No stats channels have been set up yet. Use the button below to add one.\n\n" +
+                createPageIndicator(1, 1, undefined, true)
+            );
+            pageSelect.setDisabled(true);
+            actionSelect.setDisabled(true);
+            pageSelect.addOptions(new StringSelectMenuOptionBuilder()
+                .setLabel("No stats channels")
+                .setValue("none")
+            );
         } else {
-            currentID = Object.keys(stats)[page]!
-            current = stats[currentID]!;
-            current = applyChanges({ [currentID]: current }, changes)[currentID]!;
-            // Propogate pageSelect with list of stats channels
-            for (const [id, { name, enabled }] of Object.entries(stats)) {
-                pageSelect.addOptions(
-                    new StringSelectMenuOptionBuilder()
-                        .setLabel(name)
-                        .setValue(id)
-                        .setDescription(`Enabled: ${enabled}`)
-                );
-            }
+            page = Math.min(page, Object.keys(currentObject).length - 1);
+            current = currentObject[Object.keys(config.stats)[page]!]!
             actionSelect.addOptions(new StringSelectMenuOptionBuilder()
                 .setLabel(current.enabled ? "Disable" : "Enable")
                 .setValue("toggleEnabled")
                 .setDescription(`Currently ${current.enabled ? "Enabled" : "Disabled"}, click to ${current.enabled ? "disable" : "enable"} this channel`)
                 .setEmoji(getEmojiByName(current.enabled ? "CONTROL.TICK" : "CONTROL.CROSS", "id") as APIMessageComponentEmoji)
             );
-            description = `**Currently Editing:** ${renderChannel(currentID)}\n\n` +
+
+            embed.setDescription(`**Currently Editing:** ${renderChannel(Object.keys(currentObject)[page]!)}\n\n` +
                 `${getEmojiByName(current.enabled ? "CONTROL.TICK" : "CONTROL.CROSS")} Currently ${current.enabled ? "Enabled" : "Disabled"}\n` +
                 `**Name:** \`${current.name}\`\n` +
-                `**Preview:** ${await convertCurlyBracketString(current.name, interaction.user.id, interaction.user.username, interaction.guild.name, interaction.guild.members)}`
-        }
-        const row = new ActionRowBuilder<ButtonBuilder>()
-            .addComponents(
-                new ButtonBuilder()
-                    .setCustomId("back")
-                    .setStyle(ButtonStyle.Primary)
-                    .setEmoji(getEmojiByName("CONTROL.LEFT", "id") as APIMessageComponentEmoji)
-                    .setDisabled(page === 0),
-                new ButtonBuilder()
-                    .setCustomId("next")
-                    .setEmoji(getEmojiByName("CONTROL.RIGHT", "id") as APIMessageComponentEmoji)
-                    .setStyle(ButtonStyle.Primary)
-                    .setDisabled(page === Object.keys(stats).length - 1),
-                new ButtonBuilder()
-                    .setCustomId("add")
-                    .setLabel("Create new")
-                    .setEmoji(getEmojiByName("TICKETS.SUGGESTION", "id") as APIMessageComponentEmoji)
-                    .setStyle(ButtonStyle.Secondary)
-                    .setDisabled(Object.keys(stats).length >= 24),
-                new ButtonBuilder()
-                    .setCustomId("save")
-                    .setLabel("Save")
-                    .setEmoji(getEmojiByName("ICONS.SAVE", "id") as APIMessageComponentEmoji)
-                    .setStyle(ButtonStyle.Success)
-                    .setDisabled(Object.keys(changes).length === 0),
+                `**Preview:** ${await convertCurlyBracketString(current.name, interaction.user.id, interaction.user.username, interaction.guild.name, interaction.guild.members)}` + '\n\n' +
+                createPageIndicator(Object.keys(config.stats).length, page)
             );
+            for (const [id, { name, enabled }] of Object.entries(currentObject)) {
+                pageSelect.addOptions(new StringSelectMenuOptionBuilder()
+                    .setLabel(`${name} (${renderChannel(id)})`)
+                    .setEmoji(getEmojiByName(enabled ? "CONTROL.TICK" : "CONTROL.CROSS", "id") as APIMessageComponentEmoji)
+                    .setDescription(`${enabled ? "Enabled" : "Disabled"}`)
+                    .setValue(id)
+                );
+            }
+        }
 
-        let embed = new EmojiEmbed()
-            .setTitle("Stats Channels")
-            .setDescription(description + "\n\n" + createPageIndicator(Object.keys(stats).length, page))
-            .setEmoji("SETTINGS.STATS.GREEN")
-            .setStatus("Success")
+        interaction.editReply({embeds: [embed], components: [
+            new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(pageSelect),
+            new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(actionSelect),
+            buttonRow
+        ]});
 
-        interaction.editReply({
-            embeds: [embed],
-            components: [
-                new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(pageSelect),
-                new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(actionSelect),
-                row
-            ]
-        });
-        let i: MessageComponentInteraction;
+        let i: StringSelectMenuInteraction | ButtonInteraction;
         try {
-            i = await m.awaitMessageComponent({ filter: (i) => i.user.id === interaction.user.id, time: 30000 });
+            i = await m.awaitMessageComponent({ filter: (interaction) => interaction.user.id === interaction.user.id, time: 60000 }) as StringSelectMenuInteraction | ButtonInteraction;
         } catch (e) {
             closed = true;
             continue;
         }
-        if (i.isStringSelectMenu()) {
+
+        if(i.isStringSelectMenu()) {
             switch(i.customId) {
                 case "page":
-                    page = Object.keys(stats).indexOf(i.values[0]!);
-                    i.deferUpdate();
+                    page = Object.keys(currentObject).indexOf(i.values[0]!);
                     break;
                 case "action":
-                    if(!changes[currentID]) changes[currentID] = {};
+                    modified = true;
                     switch(i.values[0]!) {
-                        case "edit":
-                            await i.showModal(
-                                new Discord.ModalBuilder()
-                                    .setCustomId("modal")
-                                    .setTitle(`Stats channel name`)
-                                    .addComponents(
-                                        new ActionRowBuilder<TextInputBuilder>().addComponents(
-                                            new TextInputBuilder()
-                                                .setCustomId("ex1")
-                                                .setLabel("Server Info (1/3)")
-                                                .setPlaceholder(
-                                                    `{serverName} - This server's name\n\n` +
-                                                    `These placeholders will be replaced with the server's name, etc..`
-                                                )
-                                                .setMaxLength(1)
-                                                .setRequired(false)
-                                                .setStyle(Discord.TextInputStyle.Paragraph)
-                                        ),
-                                        new ActionRowBuilder<TextInputBuilder>().addComponents(
-                                            new TextInputBuilder()
-                                                .setCustomId("ex2")
-                                                .setLabel("Member Counts (2/3) - {MemberCount:...}")
-                                                .setPlaceholder(
-                                                    `{:all} - Total member count\n` +
-                                                    `{:humans} - Total non-bot users\n` +
-                                                    `{:bots} - Number of bots\n`
-                                                )
-                                                .setMaxLength(1)
-                                                .setRequired(false)
-                                                .setStyle(Discord.TextInputStyle.Paragraph)
-                                        ),
-                                        new ActionRowBuilder<TextInputBuilder>().addComponents(
-                                            new TextInputBuilder()
-                                                .setCustomId("ex3")
-                                                .setLabel("Latest Member (3/3) - {member:...}")
-                                                .setPlaceholder(
-                                                        `{:name} - The members name\n`
-                                                )
-                                                .setMaxLength(1)
-                                                .setRequired(false)
-                                                .setStyle(Discord.TextInputStyle.Paragraph)
-                                        ),
-                                        new ActionRowBuilder<TextInputBuilder>().addComponents(
-                                            new TextInputBuilder()
-                                                .setCustomId("text")
-                                                .setLabel("Channel name input")
-                                                .setMaxLength(1000)
-                                                .setRequired(true)
-                                                .setStyle(Discord.TextInputStyle.Short)
-                                                .setValue(current.name)
-                                        )
-                                    )
-                            );
+                        case "edit": {
+                            showModal(i, current!)
                             await interaction.editReply({
                                 embeds: [
                                     new EmojiEmbed()
@@ -225,35 +209,24 @@
                                     )
                                 ]
                             });
-                            let out: Discord.ModalSubmitInteraction | null;
-                            try {
-                                out = await modalInteractionCollector(
-                                    m,
-                                    (m) => m.channel!.id === interaction.channel!.id,
-                                    (_) => true
-                                ) as Discord.ModalSubmitInteraction | null;
-                            } catch (e) {
-                                continue;
-                            }
-                            if (!out) continue
-                            if (!out.fields) continue
-                            if (out.isButton()) continue;
-                            const newString = out.fields.getTextInputValue("text");
-                            if (!newString) continue;
-                            changes[currentID]!.name = newString;
                             break;
-                        case "delete":
-                            changes[currentID] = {};
+                        }
+                        case "toggleEnabled": {
                             i.deferUpdate();
+                            currentObject[Object.keys(currentObject)[page]!]!.enabled = !currentObject[Object.keys(currentObject)[page]!]!.enabled;
+                            modified = true;
                             break;
-                        case "toggleEnabled":
-                            changes[currentID]!.enabled = !stats[currentID]!.enabled;
+                        }
+                        case "delete": {
                             i.deferUpdate();
+                            delete currentObject[Object.keys(currentObject)[page]!];
+                            modified = true;
                             break;
+                        }
                     }
                     break;
             }
-        } else if (i.isButton()) {
+        } else {
             i.deferUpdate();
             switch(i.customId) {
                 case "back":
@@ -265,18 +238,14 @@
                 case "add":
                     break;
                 case "save":
-                    let changed = applyChanges(config.stats, changes);
-                    singleNotify("statsChannelDeleted", interaction.guild.id, true)
-                    config.stats = changed;
-                    changes = {}
-                    await client.database.guilds.write(interaction.guildId!, config);
+                    client.database.guilds.write(interaction.guild.id, {stats: currentObject});
+                    singleNotify("statsChannelDeleted", interaction.guild.id, true);
+                    modified = false;
+                    break;
             }
         }
-        console.log(changes, config.stats);
+
     } while (!closed);
-    } catch(e) {
-        console.log(e)
-    }
 };
 
 const check = (interaction: CommandInteraction) => {
diff --git a/src/utils/createPageIndicator.ts b/src/utils/createPageIndicator.ts
index ee123d6..4ddbae2 100644
--- a/src/utils/createPageIndicator.ts
+++ b/src/utils/createPageIndicator.ts
@@ -1,17 +1,17 @@
 import getEmojiByName from "./getEmojiByName.js";
 
-function pageIndicator(amount: number, selected: number, showDetails?: boolean | true) {
+function pageIndicator(amount: number, selected: number, showDetails?: boolean, disabled?: boolean | string) {
     let out = "";
-
+    disabled = disabled ? "GREY." : ""
     if (amount === 1) {
-        out += getEmojiByName("TRACKS.SINGLE." + (selected === 0 ? "ACTIVE" : "INACTIVE"));
+        out += getEmojiByName("TRACKS.SINGLE." + (disabled) + (selected === 0 ? "ACTIVE" : "INACTIVE"));
     } else {
         for (let i = 0; i < amount; i++) {
             out += getEmojiByName(
                 "TRACKS.HORIZONTAL." +
-                    (i === 0 ? "LEFT" : i === amount - 1 ? "RIGHT" : "MIDDLE") +
-                    "." +
-                    (i === selected ? "ACTIVE" : "INACTIVE")
+                (i === 0 ? "LEFT" : i === amount - 1 ? "RIGHT" : "MIDDLE") +
+                "." + (disabled) +
+                (i === selected ? "ACTIVE" : "INACTIVE")
             );
         }
     }
