function WORincreaseBodyDirtinessByClothingDirtiness(player, wornItems, visual, bodyPartCount)
    --print("Logger: running WORincreaseBodyDirtinessByClothingDirtiness function");

    -- Dirtiness Sandbox
    local minimumClothingDirtinessRequired = SandboxVars.WashOrRot.MinimumClothingDirtinessRequired
    --print("minimumClothingDirtinessRequired: " .. minimumClothingDirtinessRequired)
    local percentage = SandboxVars.WashOrRot.ClothingDirtinessPercentageToTransfer / 100
    --print("percentage: " .. percentage)

    -- Calculate the total dirtiness from all worn clothing
    local totalClothingDirtiness = 0

    for i = 0, wornItems:size() - 1 do
        local item = wornItems:get(i):getItem()
        if item:IsClothing() then
            local itemDirtiness = item:getDirtiness()
            --print("itemDirtiness: " .. itemDirtiness)
            --print("The Item " .. item:getName() .. " has " .. itemDirtiness .. " of dirtiness")
            if itemDirtiness > minimumClothingDirtinessRequired then
                totalClothingDirtiness = totalClothingDirtiness + itemDirtiness / 100

                -- Decrease the dirtiness of the item by the percentage used for transfer
                local percentageAux = 1 - percentage
                item:setDirtiness(itemDirtiness * percentageAux)
                if item:getDirtiness() < minimumClothingDirtinessRequired then
                    item:setDirtiness(minimumClothingDirtinessRequired)
                end
            end
        end
    end

    local dirtinessPerBodyPart = (totalClothingDirtiness * percentage) / bodyPartCount
    --print("dirtinessPerBodyPart: " .. dirtinessPerBodyPart)
    local overallBodyDirtiness = 0

    -- Apply the dirtiness to each body part
    for i = 0, bodyPartCount - 1 do
        local bloodBodyPartType = BloodBodyPartType.FromIndex(i)
        local currentDirtiness = visual:getDirt(bloodBodyPartType)
        local newDirtiness = math.min(currentDirtiness + dirtinessPerBodyPart, 1)
        visual:setDirt(bloodBodyPartType, newDirtiness)
        --print("The Body Part " .. BloodBodyPartType.getDisplayName(bloodBodyPartType) .. " has " .. visual:getDirt(bloodBodyPartType) .. " of dirtiness")
        overallBodyDirtiness = overallBodyDirtiness + newDirtiness
        --print("overallBodyDirtiness: " .. overallBodyDirtiness)
    end

    return overallBodyDirtiness
end

function WORhandleDirtinessTimeUntilEffects(player, bodyOverallBodyDirtiness, dirtinessIncreaseDecreaseRateUntilEffects)
    --print("player:getModData().WORbodyDirtiness: " .. player:getModData().WORbodyDirtiness)

    -- Over 75% of body dirtiness will start to increase slighly faster the counter for the effects
    if bodyOverallBodyDirtiness > 13.5 then 
        player:getModData().WORbodyDirtiness = player:getModData().WORbodyDirtiness + (0.3 * dirtinessIncreaseDecreaseRateUntilEffects)
    -- Over 50% of body dirtiness will start to increase the counter for the effects
    elseif bodyOverallBodyDirtiness > 9 then
        player:getModData().WORbodyDirtiness = player:getModData().WORbodyDirtiness + (0.2 * dirtinessIncreaseDecreaseRateUntilEffects)
    elseif bodyOverallBodyDirtiness > 3  and bodyOverallBodyDirtiness < 9 then
    -- Under 50% of body dirtiness will start to decrease the counter for the effects
        player:getModData().WORbodyDirtiness = player:getModData().WORbodyDirtiness - (0.2 * dirtinessIncreaseDecreaseRateUntilEffects)
    else
        player:getModData().WORbodyDirtiness = 0
    end
    -- Keep the counter between 0 and 100
    if player:getModData().WORbodyDirtiness > 100 then
        player:getModData().WORbodyDirtiness = 100
    elseif player:getModData().WORbodyDirtiness < 0 then
        player:getModData().WORbodyDirtiness = 0
    end

    --print("player:getModData().WORbodyDirtiness: " .. player:getModData().WORbodyDirtiness)
end