```lua
local icol = Color(255, 255, 255, 255)
if CLIENT then
    local weapons = {"m9k_1887winchester", "m9k_1897winchester", "m9k_ares_shrike", "m9k_aw50", "m9k_barret_m82", "m9k_browningauto5", "m9k_contender", "m9k_dbarrel", "m9k_dragunov", "m9k_fg42", "m9k_intervention", "m9k_ithacam37", "m9k_jackhammer", "m9k_m3", "m9k_m24", "m9k_m60", "m9k_m98b", "m9k_m249lmg", "m9k_m1918bar", "m9k_minigun", "m9k_mossberg590", "m9k_psg1", "m9k_remington870", "m9k_remington7615p", "m9k_sl8", "m9k_svu", "m9k_usas", "m9k_spas12", "m9k_svt40", "m9k_striker12", "m9k_pkm"}
    for _, weapon in ipairs(weapons) do
        killicon.Add(weapon, "vgui/hud/" .. weapon, icol)
    end
end

local FCVAR_FLAGS = {FCVAR_REPLICATED, FCVAR_NOTIFY, FCVAR_ARCHIVE}
local function CreateConfigVar(name, defaultValue, flags, description)
    if GetConVar(name) == nil then
        CreateConVar(name, defaultValue, flags, description)
        print(name .. " con var created")
    end
end

local configVars = {{"DebugM9K", "0", "Debugging for some m9k stuff, turning it on won't change much."}, {"M9KWeaponStrip", "0", "Allow empty weapon stripping? 1 for true, 0 for false"}, {"M9KDisablePenetration", "0", "Disable Penetration and Ricochets? 1 for true, 0 for false"}, {"M9KDynamicRecoil", "1", "Use Aim-modifying recoil? 1 for true, 0 for false"}, {"M9KAmmoDetonation", "1", "Enable detonatable M9K Ammo crates? 1 for true, 0 for false."}, {"M9KDamageMultiplier", "1", "Multiplier for M9K bullet damage."}, {"M9KDefaultClip", "-1", "How many clips will a weapon spawn with? Negative reverts to default values."}, {"M9KUniqueSlots", "1", "Give M9K Weapons unique slots? 1 for true, 2 for false. A map change may be required."}}
for _, var in ipairs(configVars) do
    CreateConfigVar(var[1], var[2], FCVAR_FLAGS, var[3])
end

if not game.SinglePlayer() then
    CreateConfigVar("M9KClientGasDisable", "0", FCVAR_FLAGS, "Turn off gas effect for all clients? 1 for yes, 0 for no.")
    if SERVER then
        local function ClientSideGasDisabler()
            timer.Create("ClientGasBroadcastTimer", 15, 0, function() BroadcastLua("RunConsoleCommand(\"M9KGasEffect\", \"0\")") end)
        end

        if GetConVar("M9KClientGasDisable"):GetBool() then ClientSideGasDisabler() end
        local function M9K_Svr_Gas_Change_Callback(cvar, previous, new)
            if tobool(new) then
                ClientSideGasDisabler()
                BroadcastLua("print(\"Gas effects disabled on this server!\")")
            else
                BroadcastLua("print(\"Gas effects re-enabled on this server.\")")
                BroadcastLua("print(\"You may turn on M9KGasEffect if you wish.\")")
                if timer.Exists("ClientGasBroadcastTimer") then timer.Remove("ClientGasBroadcastTimer") end
            end
        end

        cvars.AddChangeCallback("M9KClientGasDisable", M9K_Svr_Gas_Change_Callback)
    end

    if CLIENT then CreateConfigVar("M9KGasEffect", "1", {true, true}, "Use gas effect when shooting? 1 for true, 0 for false") end
else
    CreateConfigVar("M9KGasEffect", "1", FCVAR_FLAGS, "Use gas effect when shooting? 1 for true, 0 for false")
end

local defaultVolume = 1.0
local defaultChannel = CHAN_ITEM
local function addSound(soundData)
    if not soundData.name or not soundData.soundFile then
        return
    end

    sound.Add({
        name = soundData.name,
        channel = soundData.channel or defaultChannel,
        volume = soundData.volume or defaultVolume,
        level = soundData.level or 75,
        pitch = soundData.pitch or {95, 110},
        sound = soundData.soundFile
    })
end

local function createSoundData(name, channel, soundFile)
    return {
        name = name,
        channel = channel,
        soundFile = soundFile
    }
end
```
Optimize the code and fix possible bugs, write a complete code implementation