diff --git a/src/commands/user/track.ts b/src/commands/user/track.ts
index 54af9d7..f6c1df1 100644
--- a/src/commands/user/track.ts
+++ b/src/commands/user/track.ts
@@ -1,3 +1,4 @@
+import { LoadingEmbed } from './../../utils/defaultEmbeds.js';
 import Discord, { CommandInteraction, GuildMember, Message, MessageActionRow, MessageButton } from "discord.js";
 import { SelectMenuOption, SlashCommandSubcommandBuilder } from "@discordjs/builders";
 import { WrappedCheck } from "jshaiku";
@@ -15,9 +16,9 @@
 const generateFromTrack = (position: number, active: any, size: number, disabled: any) => {
     active = active ? "ACTIVE" : "INACTIVE"
     disabled = disabled ? "GREY." : ""
-    if (position == 0 && size == 1) return "TRACKS.SINGLE." + disabled + active
-    if (position == size - 1) return "TRACKS.VERTICAL.BOTTOM." + disabled + active
-    if (position == 0) return "TRACKS.VERTICAL.TOP." + disabled + active
+    if (position === 0 && size === 1) return "TRACKS.SINGLE." + disabled + active
+    if (position === size - 1) return "TRACKS.VERTICAL.BOTTOM." + disabled + active
+    if (position === 0) return "TRACKS.VERTICAL.TOP." + disabled + active
     return "TRACKS.VERTICAL.MIDDLE." + disabled + active
 }
 
@@ -26,11 +27,7 @@
     const member = interaction.options.getMember("user") as GuildMember;
     const guild = interaction.guild;
     let config = await client.database.guilds.read(guild.id);
-    await interaction.reply({embeds: [new EmojiEmbed()
-        .setEmoji("NUCLEUS.LOADING")
-        .setTitle("Loading")
-        .setStatus("Danger")
-    ], ephemeral: true})
+    await interaction.reply({embeds: LoadingEmbed, ephemeral: true})
     let track = 0
     let generated;
     const roles = await guild.roles.fetch()
@@ -43,10 +40,10 @@
         let dropdown = new Discord.MessageSelectMenu().addOptions(config.tracks.map((option, index) => {
             let hasRoleInTrack = option.track.some(element => {return memberRoles.cache.has(element)})
             return new SelectMenuOption({
-                default: index == track,
+                default: index === track,
                 label: option.name,
                 value: index.toString(),
-                description: option.track.length == 0 ? "No" : addPlural(option.track.length, "role"),
+                description: option.track.length === 0 ? "No" : addPlural(option.track.length, "role"),
                 emoji: client.emojis.resolve(getEmojiByName("TRACKS.SINGLE." + (hasRoleInTrack ? "ACTIVE" : "INACTIVE"), "id"))
             })
         })).setCustomId("select").setMaxValues(1)
@@ -94,7 +91,7 @@
                 generated += "You don't have permission to manage one or more of the users roles, and therefore can't select one to keep."
             }
         } else {
-            currentRoleIndex = selected.length == 0 ? -1 : data.track.indexOf(selected[0].toString())
+            currentRoleIndex = selected.length === 0 ? -1 : data.track.indexOf(selected[0].toString())
         }
         let m = await interaction.editReply({embeds: [new EmojiEmbed()
             .setEmoji("TRACKS.ICON")
@@ -112,7 +109,7 @@
                     .setLabel("Move up")
                     .setCustomId("promote")
                     .setStyle("SUCCESS")
-                    .setDisabled(conflict || currentRoleIndex == 0 || (currentRoleIndex == -1 ? false : !allowed[currentRoleIndex - 1])),
+                    .setDisabled(conflict || currentRoleIndex === 0 || (currentRoleIndex === -1 ? false : !allowed[currentRoleIndex - 1])),
                 new MessageButton()
                     .setEmoji(getEmojiByName("CONTROL.DOWN", "id"))
                     .setLabel("Move down")
@@ -120,7 +117,7 @@
                     .setStyle("DANGER")
                     .setDisabled(conflict || (
                         data.nullable ? currentRoleIndex <= -1 :
-                        currentRoleIndex == data.track.length - 1 || currentRoleIndex <= -1
+                        currentRoleIndex === data.track.length - 1 || currentRoleIndex <= -1
                     ) || !allowed[currentRoleIndex]),
             ])
         ])})
@@ -131,31 +128,31 @@
             return
         }
         component.deferUpdate()
-        if (component.customId == "conflict") {
-            let rolesToRemove = selected.filter(role => role != component.values[0])
+        if (component.customId === "conflict") {
+            let rolesToRemove = selected.filter(role => role !== component.values[0])
             await member.roles.remove(rolesToRemove)
-        } else if (component.customId == "promote") {
+        } else if (component.customId === "promote") {
             if (
-                currentRoleIndex == -1 ? allowed[data.track.length - 1] :
+                currentRoleIndex === -1 ? allowed[data.track.length - 1] :
                 allowed[currentRoleIndex - 1] && allowed[currentRoleIndex]
             ) {
-                if (currentRoleIndex == -1) {
+                if (currentRoleIndex === -1) {
                     await member.roles.add(data.track[data.track.length - 1])
                 } else if (currentRoleIndex < data.track.length) {
                     if (!data.retainPrevious) await member.roles.remove(data.track[currentRoleIndex])
                     await member.roles.add(data.track[currentRoleIndex - 1])
                 }
             }
-        } else if (component.customId == "demote") {
+        } else if (component.customId === "demote") {
             if(allowed[currentRoleIndex]) {
-                if (currentRoleIndex == data.track.length - 1) {
+                if (currentRoleIndex === data.track.length - 1) {
                     if (data.nullable) await member.roles.remove(data.track[currentRoleIndex])
                 } else if (currentRoleIndex > -1) {
                     await member.roles.remove(data.track[currentRoleIndex])
                     await member.roles.add(data.track[currentRoleIndex + 1])
                 }
             }
-        } else if (component.customId == "select") {
+        } else if (component.customId === "select") {
             track = component.values[0]
         }
     }
@@ -166,7 +163,7 @@
     if (tracks.length === 0) throw "This server does not have any tracks"
     let member = (interaction.member as GuildMember)
     // Allow the owner to promote anyone
-    if (member.id == interaction.guild.ownerId) return true
+    if (member.id === interaction.guild.ownerId) return true
     // Check if the user can manage any of the tracks
     let managed = false
     tracks.forEach(element => {
@@ -174,7 +171,7 @@
         if (element.track.manageableBy.some(role => member.roles.cache.has(role))) managed = true
     });
     // Check if the user has manage_roles permission
-    if (!managed && ! member.permissions.has("MANAGE_ROLES")) throw "You do not have the Manage roles permission";
+    if (!managed && ! member.permissions.has("MANAGE_ROLES")) throw "You do not have the *Manage Roles* permission";
     // Allow track
     return true;
 }
