diff --git a/src/commands/nucleus/premium.ts b/src/commands/nucleus/premium.ts
index 325c360..c431c8e 100644
--- a/src/commands/nucleus/premium.ts
+++ b/src/commands/nucleus/premium.ts
@@ -1,74 +1,94 @@
-import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction, StringSelectMenuBuilder } from "discord.js";
+import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction, ComponentType, Message, StringSelectMenuBuilder, StringSelectMenuInteraction } from "discord.js";
 import type { SlashCommandSubcommandBuilder } from "discord.js";
 import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
 import client from "../../utils/client.js";
 import { LoadingEmbed } from "../../utils/defaults.js";
 import getEmojiByName from "../../utils/getEmojiByName.js";
-import type { PremiumSchema } from "../../utils/database.js";
 
 const command = (builder: SlashCommandSubcommandBuilder) =>
     builder.setName("premium").setDescription("Information about Nucleus Premium");
 //TODO: Allow User to remove Premium
 
-const dmcallback = async (interaction: CommandInteraction, dbUser: PremiumSchema | null, firstDescription: string): Promise<void> => {
+const dmcallback = async (interaction: CommandInteraction, firstDescription: string, msg: Message): Promise<void> => {
+    let closed = false;
+    do {
+        const dbUser = await client.database.premium.fetchUser(interaction.user.id);
+        if(!dbUser) {
+            await interaction.editReply({embeds: [
+                new EmojiEmbed()
+                    .setTitle("Premium")
+                    .setDescription(`*You do not have premium! You can't activate premium on any servers.*` + firstDescription)
+                    .setEmoji("NUCLEUS.LOGO")
+                    .setStatus("Danger")
+            ]});
+            return;
+        }
+        const premiumGuilds = dbUser.appliesTo.map((guildID) => {
+            const guild = client.guilds.cache.get(guildID);
+            if(!guild) return undefined;
+            return guild.name;
+        });
 
-    if(!dbUser) {
-        await interaction.editReply({embeds: [
-            new EmojiEmbed()
-                .setTitle("Premium")
-                .setDescription(`*You do not have premium! You can't activate premium on any servers.*` + firstDescription)
-                .setEmoji("NUCLEUS.LOGO")
-                .setStatus("Danger")
-        ]});
-        return;
-    }
-    const premiumGuilds = dbUser.appliesTo.map((guildID) => {
-        const guild = client.guilds.cache.get(guildID);
-        if(!guild) return undefined;
-        return guild.name;
-    });
+        const options = premiumGuilds.filter((guild) => guild !== undefined) as string[];
 
-    const options = premiumGuilds.filter((guild) => guild !== undefined) as string[];
+        const removeRow = new ActionRowBuilder<StringSelectMenuBuilder>()
+            .addComponents(
+                new StringSelectMenuBuilder()
+                    .setCustomId("currentPremium")
+                    .setPlaceholder("Select a server to remove premium from")
+                    .setDisabled(premiumGuilds.length === 0)
+                    .addOptions(options.slice(0, Math.min(options.length, 24)).map((guild) => {
+                        return {label: guild, value: guild}
+                    }))
+            );
+        const cancel = new ActionRowBuilder<ButtonBuilder>()
+            .addComponents(
+                new ButtonBuilder()
+                    .setCustomId("cancel")
+                    .setLabel("Close")
+                    .setStyle(ButtonStyle.Danger)
+            );
 
-    const removeRow = new ActionRowBuilder<StringSelectMenuBuilder>()
-        .addComponents(
-            new StringSelectMenuBuilder()
-                .setCustomId("currentPremium")
-                .setPlaceholder("Select a server to remove premium from")
-                .setDisabled(premiumGuilds.length === 0)
-                .addOptions(options.map((guild) => {
-                    return {label: guild, value: guild}
-                }))
-        );
-    const removeButton = new ActionRowBuilder<ButtonBuilder>()
-        .addComponents(
-            new ButtonBuilder()
-                .setCustomId("removePremium")
-                .setLabel("Remove Premium")
-                .setStyle(ButtonStyle.Danger)
-                .setDisabled(premiumGuilds.length === 0)
-        );
+        const components: ActionRowBuilder<StringSelectMenuBuilder | ButtonBuilder>[] = [cancel];
+        if(options.length > 0) components.unshift(removeRow);
+        await interaction.editReply(
+        {
+            embeds: [
+                new EmojiEmbed()
+                    .setTitle("Premium")
+                    .setDescription(
+                        `*You have premium on the following servers:*\n\n` +
+                        (options.length > 0 ? options.join(', ') : `You have not activated premium in any guilds`) +
+                        firstDescription)
+                    .setEmoji("NUCLEUS.LOGO")
+                    .setStatus("Success")
+            ],
+            components: components
+        });
 
-    await interaction.editReply(
-    {
-        embeds: [
-            new EmojiEmbed()
-                .setTitle("Premium")
-                .setDescription(`*You have premium on the following servers:*` + firstDescription)
-                .setEmoji("NUCLEUS.LOGO")
-                .setStatus("Success")
-        ],
-        components: [removeRow, removeButton]
-    });
-
-    //TODO Finish this.
-
-
+        let i: StringSelectMenuInteraction | ButtonInteraction;
+        try {
+            const filter = (i: StringSelectMenuInteraction | ButtonInteraction) => i.user.id === interaction.user.id;
+            i = await msg.awaitMessageComponent<ComponentType.StringSelect | ComponentType.Button>({time: 300000, filter})
+        } catch (e) {
+            await interaction.deleteReply();
+            closed = true;
+            break;
+        }
+        await i.deferUpdate();
+        if(i.isButton()) {
+            closed = true;
+        } else {
+            const response = client.database.premium.removePremium(interaction.user.id, i.values[0]!);
+            console.log(response)
+        }
+    } while (!closed);
+    await interaction.deleteReply();
 }
 
 const callback = async (interaction: CommandInteraction): Promise<void> => {
     if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {});
-    await interaction.reply({embeds: LoadingEmbed, ephemeral: true})
+    const m = await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true})
     const member = await (await interaction.client.guilds.fetch("684492926528651336")).members.fetch(interaction.user.id).catch(() => {
         interaction.editReply({ embeds: [
             new EmojiEmbed()
@@ -103,14 +123,13 @@
         premium = `**You can't give servers premium anymore because your subscription ended or was cancelled.** To get premium again please subscribe in the Clicks server`
         count = 0;
     }
-    if(!interaction.guild) return await dmcallback(interaction, dbMember, firstDescription);
+    if(!interaction.guild) return await dmcallback(interaction, firstDescription, m);
     const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
     let premiumGuild = ""
     if (hasPremium) {
         premiumGuild = `**This server has premium! It was ${hasPremium[2] === 3 && hasPremium[3] ? `automatically applied by <@${hasPremium[1]}>` : `given by <@${hasPremium[1]}>`}**\n\n`
     }
 
-
     const components: ActionRowBuilder<ButtonBuilder>[] = []
     if (level === 0 || dbMember?.expiresAt) {
         components.push(
@@ -144,7 +163,7 @@
                 )
                 .setEmoji("NUCLEUS.LOGO")
                 .setStatus("Danger")
-                // .setImage("") //TODO: Add image
+                .setImage("https://assets.clicks.codes/ads/ads/nucleus-premium.png")
         ],
         components: components
     });
