From bc575d40f30817ced4e55ac600cd5415687d4505 Mon Sep 17 00:00:00 2001
From: Blank <blank@national.shitposting.agency>
Date: Mon, 5 Aug 2019 21:51:03 -0700
Subject: [PATCH] RefactorSecExp-III-Crime

---
 src/002-config/fc-js-init.js                |    3 +-
 src/002-config/fc-version.js                |    4 +-
 src/SecExp/SecExpBackwardCompatibility.tw   |   16 +-
 src/SecExp/attackGenerator.tw               |    4 +-
 src/SecExp/attackHandler.tw                 |   14 +-
 src/SecExp/attackReport.tw                  |   50 +-
 src/SecExp/authorityReport.tw               |   24 +-
 src/SecExp/edicts.tw                        |  192 +-
 src/SecExp/proclamations.tw                 |    2 +-
 src/SecExp/rebellionGenerator.tw            |   42 +-
 src/SecExp/rebellionReport.tw               |   22 +-
 src/SecExp/riotControlCenter.tw             |    4 +-
 src/SecExp/secExp.js                        | 3749 +++++++++++++++++++
 src/SecExp/secExpSmilingMan.tw              |    6 +-
 src/SecExp/secInit.tw                       |    6 +-
 src/SecExp/securityHQ.tw                    |  124 +-
 src/SecExp/securityReport.tw                |   77 +-
 src/SecExp/widgets/miscSecExpWidgets.tw     |    4 +-
 src/SpecialForce/SpecialForce.js            |    6 +-
 src/uncategorized/BackwardsCompatibility.tw |    2 +-
 src/uncategorized/arcmgmt.tw                |    8 +-
 src/uncategorized/main.tw                   |    7 +-
 src/uncategorized/neighborsDevelopment.tw   |    4 +-
 src/uncategorized/options.tw                |   12 +-
 src/uncategorized/persBusiness.tw           |   14 +-
 src/uncategorized/storyCaption.tw           |  106 +-
 26 files changed, 4122 insertions(+), 380 deletions(-)
 create mode 100755 src/SecExp/secExp.js

diff --git a/src/002-config/fc-js-init.js b/src/002-config/fc-js-init.js
index 7293afed2c1..dfee0ce9b39 100644
--- a/src/002-config/fc-js-init.js
+++ b/src/002-config/fc-js-init.js
@@ -38,9 +38,10 @@ App.Facilities = {
 App.Medicine = {};
 App.RA = {};
 App.SF = {};
+App.SecExp = {};
 
 
 Object.defineProperty(App, "activeSlave", {
 	get: () => State.variables.activeSlave,
 	set: (slave) => { State.variables.activeSlave = slave; }
-});
+});
\ No newline at end of file
diff --git a/src/002-config/fc-version.js b/src/002-config/fc-version.js
index a65ccbc1721..3b0f14a44c4 100644
--- a/src/002-config/fc-version.js
+++ b/src/002-config/fc-version.js
@@ -1,8 +1,8 @@
 App.Version = {
 	base: "0.10.7",
 	pmod: "2.6.X",
-	release: 1048,
+	release: 1049,
 };
 
 /* Use release as save version */
-Config.saves.version = App.Version.release;
+Config.saves.version = App.Version.release;
\ No newline at end of file
diff --git a/src/SecExp/SecExpBackwardCompatibility.tw b/src/SecExp/SecExpBackwardCompatibility.tw
index 8efeeb27226..fc3df0dbac1 100644
--- a/src/SecExp/SecExpBackwardCompatibility.tw
+++ b/src/SecExp/SecExpBackwardCompatibility.tw
@@ -3,21 +3,7 @@
 <<set $nextButton = "Continue", $nextLink = "Main", $returnTo = "Main">>
 
 /* base stats */
-<<if ndef $authority>>
-	<<set $authority = 0>>
-<</if>>
-<<if ndef $security>>
-	<<set $security = 30>>
-<</if>>
-<<if ndef $secRestPoint>>
-	<<set $secRestPoint = 40>>
-<</if>>
-<<if ndef $crime>>
-	<<set $crime = 30>>
-<</if>>
-<<if ndef $crimeCap>>
-	<<set $crimeCap = 100>>
-<</if>>
+<<= App.SecExp.Check.general()>>
 <<if ndef $readiness>>
 	<<set $readiness = 1>>
 <</if>>
diff --git a/src/SecExp/attackGenerator.tw b/src/SecExp/attackGenerator.tw
index 3d2183b5914..ffaf58af261 100644
--- a/src/SecExp/attackGenerator.tw
+++ b/src/SecExp/attackGenerator.tw
@@ -83,12 +83,12 @@
 		<<set _free -= 8>>
 	<</if>>
 	/* raiders */
-	<<if $security <= 50>>
+	<<if $SecExp.security.cap <= 50>>
 		<<set _oldWorld -= 5>>
 		<<set _raider += 15>>
 		<<set _freeCity -= 5>>
 		<<set _free -= 5>>
-	<<elseif $security <= 25>>
+	<<elseif $SecExp.security.cap <= 25>>
 		<<set _oldWorld -= 8>>
 		<<set _raider += 24>>
 		<<set _freeCity -= 8>>
diff --git a/src/SecExp/attackHandler.tw b/src/SecExp/attackHandler.tw
index c98df00dab8..e5611f2fb5d 100644
--- a/src/SecExp/attackHandler.tw
+++ b/src/SecExp/attackHandler.tw
@@ -118,13 +118,13 @@
 
 	/* Leaders */
 	<<if $leadingTroops == "PC">>
-		<<if $authority <= 2500 && $authority > 1000>>
+		<<if $SecExp.core.authority <= 2500 && $SecExp.core.authority > 1000>>
 			<<set _slaveMod -= 0.10>>
-		<<elseif $authority <= 1000>>
+		<<elseif $SecExp.core.authority <= 1000>>
 			<<set _slaveMod -= 0.25>>
-		<<elseif $authority >= 5000 && $authority < 15000>>
+		<<elseif $SecExp.core.authority >= 5000 && $SecExp.core.authority < 15000>>
 			<<set _slaveMod += 0.10>>
-		<<elseif $authority >= 15000>>
+		<<elseif $SecExp.core.authority >= 15000>>
 			<<set _slaveMod += 0.25>>
 		<</if>>
 		<<if $PC.career == "escort" || $PC.career == "servant">>
@@ -214,7 +214,7 @@
 			<<set $PCWounded = 1>>
 		<</if>>
 	<<elseif $leadingTroops == "assistant">>
-		<<if $rep < 10000 && $authority < 10000>>
+		<<if $rep < 10000 && $SecExp.core.authority < 10000>>
 			<<set _militiaMod -= 0.15>>
 			<<set _slaveMod -= 0.15>>
 			<<set _mercMod -= 0.15>>
@@ -239,7 +239,7 @@
 		<<elseif $Bodyguard.devotion > 50>>
 			<<set _slaveMod += 0.15>>
 		<</if>>
-		<<if ($rep < 10000 && $authority < 10000) || $Bodyguard.prestige < 1>>
+		<<if ($rep < 10000 && $SecExp.core.authority < 10000) || $Bodyguard.prestige < 1>>
 			<<set _militiaMod -= 0.15>>
 			<<set _mercMod -= 0.15>>
 			<<set _SFMod -= 0.15>>
@@ -367,7 +367,7 @@
 		<<elseif $HeadGirl.devotion > 51>>
 			<<set _slaveMod += 0.15>>
 		<</if>>
-		<<if ($rep < 10000 && $authority < 10000) || $HeadGirl.prestige < 1>>
+		<<if ($rep < 10000 && $SecExp.core.authority < 10000) || $HeadGirl.prestige < 1>>
 			<<set _militiaMod -= 0.15>>
 			<<set _mercMod -= 0.15>>
 			<<set _SFMod -= 0.15>>
diff --git a/src/SecExp/attackReport.tw b/src/SecExp/attackReport.tw
index dfb954e2a3f..62474260951 100644
--- a/src/SecExp/attackReport.tw
+++ b/src/SecExp/attackReport.tw
@@ -4,7 +4,7 @@
 
 /*init*/
 <<set _oldRep = $rep>>
-<<set _oldAuth = $authority>>
+<<set _oldAuth = $SecExp.core.authority>>
 <<set $enemyLosses = Math.trunc($enemyLosses)>>
 <<if $enemyLosses > $attackTroops>>
 	<<set $enemyLosses = $attackTroops>>
@@ -384,16 +384,16 @@
 	Thanks to your victory, your @@.green;reputation@@ and @@.darkviolet;authority@@ increased. You were also able to capture
 	<<if $attackType == "raiders">>
 		<<run repX(4000 * _majorBattleMod, "war")>>
-		<<set $authority += 800 * _majorBattleMod>>
+		<<set $SecExp.core.authority += 800 * _majorBattleMod>>
 	<<elseif $attackType == "free city">>
 		<<run repX(6000 * _majorBattleMod, "war")>>
-		<<set $authority += 1200 * _majorBattleMod>>
+		<<set $SecExp.core.authority += 1200 * _majorBattleMod>>
 	<<elseif $attackType == "freedom fighters">>
 		<<run repX(7500 * _majorBattleMod, "war")>>
-		<<set $authority += 1500 * _majorBattleMod>>
+		<<set $SecExp.core.authority += 1500 * _majorBattleMod>>
 	<<elseif $attackType == "old world">>
 		<<run repX(6000 * _majorBattleMod, "war")>>
-		<<set $authority += 1200 * _majorBattleMod>>
+		<<set $SecExp.core.authority += 1200 * _majorBattleMod>>
 	<</if>>
 	<<if $attackTroops - $enemyLosses <= 50>>
 		a small amount of attackers,
@@ -446,16 +446,16 @@
 	Due to your defeat, your @@.red;reputation@@ and @@.red;authority@@ decreased. Obviously your troops were not able to capture anyone or anything.
 	<<if $attackType == "raiders">>
 		<<run repX(forceNeg(400 * _majorBattleMod), "war")>>
-		<<set $authority -= 400 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 400 * _majorBattleMod>>
 	<<elseif $attackType == "free city">>
 		<<run repX(forceNeg(600 * _majorBattleMod), "war")>>
-		<<set $authority -= 600 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 600 * _majorBattleMod>>
 	<<elseif $attackType == "freedom fighters">>
 		<<run repX(forceNeg(750 * _majorBattleMod), "war")>>
-		<<set $authority -= 750 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 750 * _majorBattleMod>>
 	<<elseif $attackType == "old world">>
 		<<run repX(forceNeg(600 * _majorBattleMod), "war")>>
-		<<set $authority -= 600 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 600 * _majorBattleMod>>
 	<</if>>
 	<br>
 	In the raiding following the battle @@.red;the arcology sustained heavy damage,@@ which will cost quite the amount of cash to fix. Reports of @@.red;citizens or slaves killed or missing@@ flood your office for a few days following the defeat.
@@ -510,16 +510,16 @@
 	Thanks to your victory, your @@.green;reputation@@ and @@.darkviolet;authority@@ slightly increased. Our men were not able to capture any combatants, however some equipment was seized during the enemy's hasty retreat,
 	<<if $attackType == "raiders">>
 		<<run repX(1000 * _majorBattleMod, "war")>>
-		<<set $authority += 200 * _majorBattleMod>>
+		<<set $SecExp.core.authority += 200 * _majorBattleMod>>
 	<<elseif $attackType == "free city">>
 		<<run repX(1500 * _majorBattleMod, "war")>>
-		<<set $authority += 300 * _majorBattleMod>>
+		<<set $SecExp.core.authority += 300 * _majorBattleMod>>
 	<<elseif $attackType == "freedom fighters">>
 		<<run repX(2000 * _majorBattleMod, "war")>>
-		<<set $authority += 450 * _majorBattleMod>>
+		<<set $SecExp.core.authority += 450 * _majorBattleMod>>
 	<<elseif $attackType == "old world">>
 		<<run repX(1500 * _majorBattleMod, "war")>>
-		<<set $authority += 300 * _majorBattleMod>>
+		<<set $SecExp.core.authority += 300 * _majorBattleMod>>
 	<</if>>
 	which once sold produced
 	<<if $attackEquip == 0>>
@@ -557,16 +557,16 @@
 	It was a close defeat, but nonetheless your @@.red;reputation@@ and @@.red;authority@@ slightly decreased. Your troops were not able to capture anyone or anything.
 	<<if $attackType == "raiders">>
 		<<run repX(forceNeg(40 * _majorBattleMod), "war")>>
-		<<set $authority -= 40 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 40 * _majorBattleMod>>
 	<<elseif $attackType == "free city">>
 		<<run repX(forceNeg(60 * _majorBattleMod), "war")>>
-		<<set $authority -= 60 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 60 * _majorBattleMod>>
 	<<elseif $attackType == "freedom fighters">>
 		<<run repX(forceNeg(75 * _majorBattleMod), "war")>>
-		<<set $authority -= 75 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 75 * _majorBattleMod>>
 	<<elseif $attackType == "old world">>
 		<<run repX(forceNeg(60 * _majorBattleMod), "war")>>
-		<<set $authority -= 60 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 60 * _majorBattleMod>>
 	<</if>>
 	<br>
 	The enemy did not have the strength to raid the arcology for long, still @@.red;the arcology sustained some damage,@@ which will cost a moderate amount of cash to fix. Some citizens and slaves found themselves on the wrong end of a gun and met their demise.
@@ -618,16 +618,16 @@
 	Rather than waste the lives of your men you decided to surrender, hoping your enemy will cause less damage if you indulge them, this is however a big hit to your status. Your @@.red;reputation@@ and @@.red;authority@@ are significantly impacted.
 	<<if $attackType == "raiders">>
 		<<run repX(forceNeg(600 * _majorBattleMod), "war")>>
-		<<set $authority -= 600 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 600 * _majorBattleMod>>
 	<<elseif $attackType == "free city">>
 		<<run repX(forceNeg(800 * _majorBattleMod), "war")>>
-		<<set $authority -= 800 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 800 * _majorBattleMod>>
 	<<elseif $attackType == "freedom fighters">>
 		<<run repX(forceNeg(1000 * _majorBattleMod), "war")>>
-		<<set $authority -= 1000 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 1000 * _majorBattleMod>>
 	<<elseif $attackType == "old world">>
 		<<run repX(forceNeg(800 * _majorBattleMod), "war")>>
-		<<set $authority -= 800 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 800 * _majorBattleMod>>
 	<</if>>
 	<br>
 	The surrender allows the arcology to survive @@.red;mostly intact,@@ however reports of @@.red;mass looting and killing of citizens@@ flood your office for a few days.
@@ -679,16 +679,16 @@
 	Your reputation and authority suffer a hit.
 	<<if $attackType == "raiders">>
 		<<run repX(forceNeg(400 * _majorBattleMod), "war")>>
-		<<set $authority -= 400 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 400 * _majorBattleMod>>
 	<<elseif $attackType == "free city">>
 		<<run repX(forceNeg(600 * _majorBattleMod), "war")>>
-		<<set $authority -= 600 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 600 * _majorBattleMod>>
 	<<elseif $attackType == "freedom fighters">>
 		<<run repX(forceNeg(750 * _majorBattleMod), "war")>>
-		<<set $authority -= 750 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 750 * _majorBattleMod>>
 	<<elseif $attackType == "old world">>
 		<<run repX(forceNeg(600 * _majorBattleMod), "war")>>
-		<<set $authority -= 600 * _majorBattleMod>>
+		<<set $SecExp.core.authority -= 600 * _majorBattleMod>>
 	<</if>>
 	<br>
 	Fortunately the arcology survives @@.yellow;mostly intact,@@ however reports of @@.red;mass looting and killing of citizens@@ flood your office for a few days.
diff --git a/src/SecExp/authorityReport.tw b/src/SecExp/authorityReport.tw
index b56e08c95f4..a0bafc5103e 100644
--- a/src/SecExp/authorityReport.tw
+++ b/src/SecExp/authorityReport.tw
@@ -3,13 +3,13 @@
 <<if $useTabs == 0>>__Authority__<</if>>
 <br>
 Your authority is
-<<if $authority > 19500>>
+<<if $SecExp.core.authority > 19500>>
 	nearly absolute. The arcology is yours to command as it pleases you.
-<<elseif $authority > 15000>>
+<<elseif $SecExp.core.authority > 15000>>
 	extremely high. There's little you cannot do within the walls of your arcology.
-<<elseif $authority > 10000>>
+<<elseif $SecExp.core.authority > 10000>>
 	high. You command respect and fear in equal measure.
-<<elseif $authority > 5000>>
+<<elseif $SecExp.core.authority > 5000>>
 	moderate. You command some respect from your citizens.
 <<else>>
 	low. You command no respect or fear from your citizens.
@@ -48,24 +48,24 @@ Your authority is
 	<<set _authGrowth += (10 * random(2,8))>>
 <</if>>
 
-<<if $security >= 90>>
+<<if $SecExp.security.cap >= 90>>
 	Your arcology is incredibly secure and your citizens know quite well who to thank, greatly increasing your authority.
 	<<set _authGrowth += (10 * random(10,20))>>
-<<elseif $security >= 70>>
+<<elseif $SecExp.security.cap >= 70>>
 	Your arcology is really secure and your citizens know quite well who to thank, increasing your authority.
 	<<set _authGrowth += (10 * random(5,15))>>
-<<elseif $security >= 50>>
+<<elseif $SecExp.security.cap >= 50>>
 	Your arcology is quite secure and your citizens know who to thank, increasing your authority.
 	<<set _authGrowth += (10 * random(2,8))>>
 <</if>>
 
-<<if $crime >= 90>>
+<<if $SecExp.core.crimeLow >= 90>>
 	The all powerful criminal organizations controlling the arcology have a very easy time undermining your authority.
 	<<set _authGrowth -= (10 * random(10,20))>>
-<<elseif $crime >= 70>>
+<<elseif $SecExp.core.crimeLow >= 70>>
 	Crime is king in the arcology, powerful criminals have a very easy time undermining your authority.
 	<<set _authGrowth -= (10 * random(5,15))>>
-<<elseif $crime >= 50>>
+<<elseif $SecExp.core.crimeLow >= 50>>
 	Criminal organizations have a strong foothold in the arcology, their activities undermine your authority.
 	<<set _authGrowth -= (10 * random(2,8))>>
 <</if>>
@@ -167,8 +167,8 @@ This week
 	@@.red;authority has decreased.@@
 <</if>>
 
-<<set $authority += _authGrowth>>
-<<set $authority = Math.trunc(Math.clamp($authority, 0, 20000))>>
+<<set $SecExp.core.authority += _authGrowth>>
+<<set $SecExp.core.authority = Math.trunc(Math.clamp($SecExp.core.authority, 0, 20000))>>
 
 <<if $rebellionsEnabled == 1>>
 /* rebellions */
diff --git a/src/SecExp/edicts.tw b/src/SecExp/edicts.tw
index 7796710d8dc..dd898417116 100644
--- a/src/SecExp/edicts.tw
+++ b/src/SecExp/edicts.tw
@@ -222,8 +222,8 @@
 <br>
 <<if $alternativeRents == 0>>
 	<br>''Alternative rent payment:'' allow citizens to pay for their rents in menial slaves rather than cash, if so they wish.
-	<<if $authority >= 1000>>
-		[[Implement|edicts][$alternativeRents = 1, cashX(-5000, "edicts"), $authority -= 1000]]
+	<<if $SecExp.core.authority >= 1000>>
+		[[Implement|edicts][$alternativeRents = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 	<<else>>
 		<br>//Not enough Authority.//
 	<</if>>
@@ -232,8 +232,8 @@
 
 <<if $enslavementRights == 0>>
 	<br>''Enslavement rights:'' the arcology owner will be the only authority able to declare a person enslaved or not.
-	<<if $authority >= 1000>>
-		[[Implement|edicts][$enslavementRights = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsAuthUpkeep += 10]]
+	<<if $SecExp.core.authority >= 1000>>
+		[[Implement|edicts][$enslavementRights = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsAuthUpkeep += 10]]
 	<<else>>
 		<br>//Not enough Authority.//
 	<</if>>
@@ -242,8 +242,8 @@
 
 <<if $sellData == 0 && ($secUpgrades.nanoCams == 1 || $secUpgrades.cyberBots == 1 || $secUpgrades.eyeScan == 1 || $secUpgrades.cryptoAnalyzer == 1 || $crimeUpgrades.autoTrial == 1 || $crimeUpgrades.autoArchive == 1 || $crimeUpgrades.worldProfiler == 1 || $crimeUpgrades.advForensic == 1)>>
 	<br>''Private Data marketization:'' allow the selling of private citizens' data.
-	<<if $authority >= 1000>>
-		[[Implement|edicts][$sellData = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsAuthUpkeep += 10]]
+	<<if $SecExp.core.authority >= 1000>>
+		[[Implement|edicts][$sellData = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsAuthUpkeep += 10]]
 	<<else>>
 		<br>//Not enough Authority.//
 	<</if>>
@@ -253,8 +253,8 @@
 <<if $propHub == 1>>
 	<<if $propCampaignBoost == 0>>
 		<br>''Obligatory educational material:'' force residents to read curated educational material about the arcology.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$propCampaignBoost = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsUpkeep += 1000]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$propCampaignBoost = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsUpkeep += 1000]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
@@ -265,8 +265,8 @@
 <<if $transportHub == 1>>
 	<<if $tradeLegalAid == 0>>
 		<br>''Legal aid for new businesses:'' Support new businesses in the arcology by helping them cover legal costs and issues.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$tradeLegalAid = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsUpkeep += 1000]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$tradeLegalAid = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsUpkeep += 1000]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
@@ -274,8 +274,8 @@
 	<</if>>
 	<<if $taxTrade == 0>>
 		<br>''Trade tariffs:'' all goods transitioning in your arcology will have to pay a transition fee.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$taxTrade = 1, cashX(-5000, "edicts"), $authority -= 1000]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$taxTrade = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
@@ -286,8 +286,8 @@
 <<if $arcologies[0].FSPaternalist != "unset">>
 	<<if $slaveWatch == 0>>
 		<br>''@@.lime;Slave mistreatment watch:@@'' slaves will be able access a special security service in case of mistreatment.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$slaveWatch = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsUpkeep += 1000]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$slaveWatch = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsUpkeep += 1000]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
@@ -298,8 +298,8 @@
 <<if $arcologies[0].FSChattelReligionist >= 40>>
 	<<if $subsidyChurch == 0>>
 		<br>''@@.lime;Religious activities subsidy:@@'' will provide economic support to religious activities following the official dogma.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$subsidyChurch = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsUpkeep += 1000]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$subsidyChurch = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsUpkeep += 1000]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
@@ -311,40 +311,40 @@
 	<br><br>__Special Force:__
 	<<if !$SFSupportLevel && $reqMenials > 5>>
 		<br>''Equipment provision:'' $SF.Caps will provide the security HQ with advanced equipment.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$SFSupportLevel++, cashX(-5000, "edicts"), $authority -= 1000, $SFSupportUpkeep += 1000, $reqMenials -= 5]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$SFSupportLevel++, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $SFSupportUpkeep += 1000, $reqMenials -= 5]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
 		<br>&nbsp;&nbsp;&nbsp;&nbsp;//Will lower the amount of personnel necessary to man the security HQ by 5, but will incur upkeep costs.//
 	<<elseif $SFSupportLevel && $SF.Squad.Firebase >= 4 && $reqMenials > 5>>
 		<br>''Personnel training:'' $SF.Caps will provide the security HQ personnel with advanced training.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$SFSupportLevel++, cashX(-5000, "edicts"), $authority -= 1000, $SFSupportUpkeep += 2000, $reqMenials -= 5]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$SFSupportLevel++, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $SFSupportUpkeep += 2000, $reqMenials -= 5]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
 		<br>&nbsp;&nbsp;&nbsp;&nbsp;//Will lower the amount of personnel necessary to man the security HQ by a further 5, but will incur additional upkeep costs.//
 	<<elseif $SFSupportLevel === 2 && $SF.Squad.Firebase >= 6 && $reqMenials > 5>>
 		<br>''Troops detachment:'' $SF.Caps will provide troops to the security department.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$SFSupportLevel++, cashX(-5000, "edicts"), $authority -= 1000, $SFSupportUpkeep += 3000, $reqMenials -= 5]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$SFSupportLevel++, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $SFSupportUpkeep += 3000, $reqMenials -= 5]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
 		<br>&nbsp;&nbsp;&nbsp;&nbsp;//Will lower the amount of personnel necessary to man the security HQ by a further 5, but will incur additional upkeep costs.//
 	<<elseif $SFSupportLevel === 3 && $SF.Squad.Firebase >= 6 && $reqMenials > 5>>
 		<br>''Full Support:'' $SF.Caps will give the security department its full support.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$SFSupportLevel++, cashX(-5000, "edicts"), $authority -= 1000, $SFSupportUpkeep += 3000, $reqMenials -= 5]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$SFSupportLevel++, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $SFSupportUpkeep += 3000, $reqMenials -= 5]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
 		<br>&nbsp;&nbsp;&nbsp;&nbsp;//Will lower the amount of personnel necessary to man the security HQ by a further 5, but will incur additional upkeep costs.//
 	<<elseif $SFSupportLevel === 4 && $SF.Squad.Firebase === 10 && $reqMenials > 5>>
 		<br>''Network assistance:'' $SF.Caps will assist the security department with installing a local version of their custom network.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$SFSupportLevel++, cashX(-50000, "edicts"), $authority -= 1000, $SFSupportUpkeep += 4000, $secHQUpkeep += 1000, $reqMenials -= 5]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$SFSupportLevel++, cashX(-50000, "edicts"), $SecExp.core.authority -= 1000, $SFSupportUpkeep += 4000, $secHQUpkeep += 1000, $reqMenials -= 5]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
@@ -356,8 +356,8 @@
 
 <<if $limitImmigration == 0>>
 	<br>''Immigration limits:'' institute limits to the amount of people the arcology will accept each week.
-	<<if $authority >= 1000>>
-		[[Implement|edicts][$openBorders = 0, $limitImmigration = 1, cashX(-5000, "edicts"), $authority -= 1000]]
+	<<if $SecExp.core.authority >= 1000>>
+		[[Implement|edicts][$openBorders = 0, $limitImmigration = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 	<<else>>
 		<br>//Not enough Authority.//
 	<</if>>
@@ -366,8 +366,8 @@
 
 <<if $openBorders == 0>>
 	<br>''Open borders:'' considerably lower requirements to become citizens.
-	<<if $authority >= 1000>>
-		[[Implement|edicts][$openBorders = 1, $limitImmigration = 0, cashX(-5000, "edicts"), $authority -= 1000]]
+	<<if $SecExp.core.authority >= 1000>>
+		[[Implement|edicts][$openBorders = 1, $limitImmigration = 0, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 	<<else>>
 		<br>//Not enough Authority.//
 	<</if>>
@@ -377,46 +377,46 @@
 <br><br>__Weapons:__
 <<if $weaponsLaw == 3>>
 	<br>''Heavy weaponry forbidden:'' set the range of weapons allowed within the arcology to non-heavy, non-explosive.
-	<<if $authority >= 1000>>
-		[[Implement|edicts][$weaponsLaw = 2, cashX(-5000, "edicts"), $authority -= 1000, $edictsAuthUpkeep += 10]]
+	<<if $SecExp.core.authority >= 1000>>
+		[[Implement|edicts][$weaponsLaw = 2, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsAuthUpkeep += 10]]
 	<<else>>
 		<br>//Not enough Authority.//
 	<</if>>
 	<br>&nbsp;&nbsp;&nbsp;&nbsp;//Will slightly increase prosperity, but will cost a small amount of authority each week and will leave rebellions decently armed.//
 <<elseif $weaponsLaw == 2>>
 	<br>''All weapons allowed:'' allow residents of the arcology to buy, sell and keep weaponry of any kind within the arcology.
-	<<if $authority >= 1000>>
-		[[Implement|edicts][$weaponsLaw = 3, cashX(-5000, "edicts"), $authority -= 1000, $edictsAuthUpkeep -= 10]]
+	<<if $SecExp.core.authority >= 1000>>
+		[[Implement|edicts][$weaponsLaw = 3, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsAuthUpkeep -= 10]]
 	<<else>>
 		<br>//Not enough Authority.//
 	<</if>>
 	<br>&nbsp;&nbsp;&nbsp;&nbsp;//Will slightly increase prosperity and provide a small weekly amount of reputation, but rebellions will be very well armed.//
 	<br>''Heavily restricted weaponry:'' set the range of weapons allowed within the arcology to non-automatic, non-high caliber.
-	<<if $authority >= 1000>>
-		[[Implement|edicts][$weaponsLaw = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsAuthUpkeep += 10]]
+	<<if $SecExp.core.authority >= 1000>>
+		[[Implement|edicts][$weaponsLaw = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsAuthUpkeep += 10]]
 	<<else>>
 		<br>//Not enough Authority.//
 	<</if>>
 	<br>&nbsp;&nbsp;&nbsp;&nbsp;//Will cost some authority each week, but rebellions will be poorly armed.//
 <<elseif $weaponsLaw == 1>>
 	<br>''Heavy weaponry forbidden:'' set the range of weapons allowed within the arcology to non-heavy, non-explosive.
-	<<if $authority >= 1000>>
-		[[Implement|edicts][$weaponsLaw = 2, cashX(-5000, "edicts"), $authority -= 1000, $edictsAuthUpkeep -= 10]]
+	<<if $SecExp.core.authority >= 1000>>
+		[[Implement|edicts][$weaponsLaw = 2, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsAuthUpkeep -= 10]]
 	<<else>>
 		<br>//Not enough Authority.//
 	<</if>>
 	<br>&nbsp;&nbsp;&nbsp;&nbsp;//Will slightly increase prosperity, but will cost a small amount of authority each week and will leave rebellions decently armed.//
 	<br>''Forbid weapons inside the arcology:'' forbid residents to buy, sell and keep weaponry while within the arcology.
-	<<if $authority >= 1000>>
-		[[Implement|edicts][$weaponsLaw = 0, cashX(-5000, "edicts"), $authority -= 1000, $edictsAuthUpkeep += 10]]
+	<<if $SecExp.core.authority >= 1000>>
+		[[Implement|edicts][$weaponsLaw = 0, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsAuthUpkeep += 10]]
 	<<else>>
 		<br>//Not enough Authority.//
 	<</if>>
 	<br>&nbsp;&nbsp;&nbsp;&nbsp;//Will cost a moderate amount of authority each week, but rebellions will be very poorly armed.//
 <<elseif $weaponsLaw == 0>>
 	<br>''Heavily restricted weaponry:'' set the range of weapons allowed within the arcology to non-automatic, non-high caliber.
-	<<if $authority >= 1000>>
-		[[Implement|edicts][$weaponsLaw = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsAuthUpkeep -= 10]]
+	<<if $SecExp.core.authority >= 1000>>
+		[[Implement|edicts][$weaponsLaw = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsAuthUpkeep -= 10]]
 	<<else>>
 		<br>//Not enough Authority.//
 	<</if>>
@@ -428,31 +428,31 @@
 
 	<<if $soldierWages == 0>>
 		<br>''Average wages for soldiers:'' will set the wages paid to the soldiers of the arcology to an average amount.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$soldierWages += 1, cashX(-5000, "edicts"), $authority -= 1000]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$soldierWages += 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
 		<br>&nbsp;&nbsp;&nbsp;&nbsp;//Will raise all units upkeep and push loyalty to average levels.//
 	<<elseif $soldierWages == 1>>
 		<br>''Low wages for soldiers:'' will set the wages paid to the soldiers of the arcology to a low amount.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$soldierWages -= 1, cashX(-5000, "edicts"), $authority -= 1000]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$soldierWages -= 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
 		<br>&nbsp;&nbsp;&nbsp;&nbsp;//Will lower all units upkeep and push loyalty to low levels.//
 		<br>''High wages for soldiers:'' will set the wages paid to the soldiers of the arcology to a high amount.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$soldierWages += 1, cashX(-5000, "edicts"), $authority -= 1000]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$soldierWages += 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
 		<br>&nbsp;&nbsp;&nbsp;&nbsp;//Will raise all units upkeep and push loyalty to high levels.//
 	<<else>>
 		<br>''Average wages for soldiers:'' will set the wages paid to the soldiers of the arcology to an average amount.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$soldierWages -= 1, cashX(-5000, "edicts"), $authority -= 1000]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$soldierWages -= 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
@@ -461,8 +461,8 @@
 
 	<<if $slavesOfficers == 0>>
 		<br>''Slave Officers:'' allow your trusted slaves to lead the defense forces of the arcology.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$slavesOfficers = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsAuthUpkeep += 10]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$slavesOfficers = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsAuthUpkeep += 10]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
@@ -472,8 +472,8 @@
 	<<if $mercenaries > 0>>
 		<<if $discountMercenaries == 0>>
 			<br>''Mercenary subsidy:'' mercenaries willing to immigrate in your arcology will be offered a discount on rent.
-			<<if $authority >= 1000>>
-				[[Implement|edicts][$discountMercenaries = 1, cashX(-5000, "edicts"), $authority -= 1000]]
+			<<if $SecExp.core.authority >= 1000>>
+				[[Implement|edicts][$discountMercenaries = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -483,8 +483,8 @@
 
 	<<if $militiaFounded == 0>>
 		<br>''Found the militia:'' lay the groundwork for the formation of the arcology's citizens' army.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$militiaFounded = 1, $recruitVolunteers = 1, cashX(-5000, "edicts"), $authority -= 1000]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$militiaFounded = 1, $recruitVolunteers = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
@@ -494,8 +494,8 @@
 	<<if $militiaFounded == 1>>
 		<<if $recruitVolunteers == 0>>
 			<br>''Volunteers' militia:'' only volunteers will be accepted in the militia.
-			<<if $authority >= 1000>>
-				[[Implement|edicts][$militarizedSociety = 0, $militaryService = 0, $conscription = 0, $recruitVolunteers = 1, cashX(-5000, "edicts"), $authority -= 1000]]
+			<<if $SecExp.core.authority >= 1000>>
+				[[Implement|edicts][$militarizedSociety = 0, $militaryService = 0, $conscription = 0, $recruitVolunteers = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -503,8 +503,8 @@
 		<</if>>
 		<<if $conscription == 0>>
 			<br>''Conscription:'' every citizen is required to train in the militia and serve the arcology if the need arises.
-			<<if $authority >= 4000>>
-				[[Implement|edicts][$militarizedSociety = 0, $militaryService = 0, $conscription = 1, $recruitVolunteers = 0, cashX(-5000, "edicts"), $authority -= 4000]]
+			<<if $SecExp.core.authority >= 4000>>
+				[[Implement|edicts][$militarizedSociety = 0, $militaryService = 0, $conscription = 1, $recruitVolunteers = 0, cashX(-5000, "edicts"), $SecExp.core.authority -= 4000]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -512,8 +512,8 @@
 		<</if>>
 		<<if $militaryService == 0>>
 			<br>''Obligatory military service:'' every citizen is required to register and serve under the militia.
-			<<if $authority >= 6000>>
-				[[Implement|edicts][$militarizedSociety = 0, $militaryService = 1, $conscription = 0, $recruitVolunteers = 0, cashX(-5000, "edicts"), $authority -= 6000]]
+			<<if $SecExp.core.authority >= 6000>>
+				[[Implement|edicts][$militarizedSociety = 0, $militaryService = 1, $conscription = 0, $recruitVolunteers = 0, cashX(-5000, "edicts"), $SecExp.core.authority -= 6000]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -521,8 +521,8 @@
 		<</if>>
 		<<if $militarizedSociety == 0>>
 			<br>''Militarized Society:'' every adult citizen is required to train and participate in the defense of the arcology.
-			<<if $authority >= 8000>>
-				[[Implement|edicts][$militarizedSociety = 1, $militaryService = 0, $conscription = 0, $recruitVolunteers = 0, cashX(-5000, "edicts"), $authority -= 8000]]
+			<<if $SecExp.core.authority >= 8000>>
+				[[Implement|edicts][$militarizedSociety = 1, $militaryService = 0, $conscription = 0, $recruitVolunteers = 0, cashX(-5000, "edicts"), $SecExp.core.authority -= 8000]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -531,8 +531,8 @@
 
 		<<if $militaryExemption == 0 && ($conscription == 1 || $militaryService == 1 || $militarizedSociety == 1)>>
 			<br>''Military exemption:'' allow citizens to avoid military duty by paying a weekly fee.
-			<<if $authority >= 1000>>
-				[[Implement|edicts][$militaryExemption = 1, cashX(-5000, "edicts"), $authority -= 1000]]
+			<<if $SecExp.core.authority >= 1000>>
+				[[Implement|edicts][$militaryExemption = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -542,8 +542,8 @@
 		<<if $arcologies[0].FSHedonisticDecadence >= 40>>
 			<<if $lowerRquirements == 0>>
 				<br>''@@.lime;Revised minimum requirements:@@'' will allow citizens outside the normally accepted range to join the militia.
-				<<if $authority >= 1000>>
-					[[Implement|edicts][$lowerRquirements = 1, cashX(-5000, "edicts"), $authority -= 1000, $militiaBaseDefense--, $militiaBaseHp--]]
+				<<if $SecExp.core.authority >= 1000>>
+					[[Implement|edicts][$lowerRquirements = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $militiaBaseDefense--, $militiaBaseHp--]]
 				<<else>>
 					<br>//Not enough Authority.//
 				<</if>>
@@ -554,8 +554,8 @@
 		<<if $arcologies[0].FSSubjugationist >= 40>>
 			<<if $noSubhumansInArmy == 0>>
 				<br>''@@.lime;No subhumans in the militia:@@'' prevent subhumans from joining the militia.
-				<<if $authority >= 1000>>
-					[[Implement|edicts][$noSubhumansInArmy = 1, cashX(-5000, "edicts"), $authority -= 1000]]
+				<<if $SecExp.core.authority >= 1000>>
+					[[Implement|edicts][$noSubhumansInArmy = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 				<<else>>
 					<br>//Not enough Authority.//
 				<</if>>
@@ -566,8 +566,8 @@
 		<<if $arcologies[0].FSRepopulationFocus >= 40 && ($conscription == 1 || $militaryService == 1 || $militarizedSociety == 1)>>
 			<<if $pregExemption == 0>>
 				<br>''@@.lime;Military exemption for pregnancies:@@'' pregnant citizens will be allowed, and encouraged, to avoid military service.
-				<<if $authority >= 1000>>
-					[[Implement|edicts][$pregExemption = 1, cashX(-5000, "edicts"), $authority -= 1000]]
+				<<if $SecExp.core.authority >= 1000>>
+					[[Implement|edicts][$pregExemption = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 				<<else>>
 					<br>//Not enough Authority.//
 				<</if>>
@@ -578,8 +578,8 @@
 
 	<<if $militiaSoldierPrivilege == 0 && $militiaFounded == 1>>
 		<br>''Special militia privileges'' will allow citizens joining the militia to avoid paying rent.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$militiaSoldierPrivilege = 1, cashX(-5000, "edicts"), $authority -= 1000]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$militiaSoldierPrivilege = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
@@ -588,8 +588,8 @@
 
 	<<if $slaveSoldierPrivilege == 0>>
 		<br>''Special slaves privileges'' will allow slaves drafted into the army to be able to have material possessions.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$slaveSoldierPrivilege = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsAuthUpkeep += 10]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$slaveSoldierPrivilege = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsAuthUpkeep += 10]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
@@ -598,8 +598,8 @@
 
 	<<if $mercSoldierPrivilege == 0 && $mercenaries > 0>>
 		<br>''Special mercenary privileges'' will allow mercenaries under contract to claim part of the loot gained from battles.
-		<<if $authority >= 1000>>
-			[[Implement|edicts][$mercSoldierPrivilege = 1, cashX(-5000, "edicts"), $authority -= 1000]]
+		<<if $SecExp.core.authority >= 1000>>
+			[[Implement|edicts][$mercSoldierPrivilege = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 		<<else>>
 			<br>//Not enough Authority.//
 		<</if>>
@@ -609,8 +609,8 @@
 	<<if $arcologies[0].FSPhysicalIdealist >= 40>>
 		<<if $martialSchool == 0>>
 			<br>''@@.lime;Slave martial schools:@@'' specialized schools will be set up to train slaves in martial arts and bodyguarding.
-			<<if $authority >= 1000>>
-				[[Implement|edicts][$martialSchool = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsUpkeep += 1000, $slaveBaseMorale += 5]]
+			<<if $SecExp.core.authority >= 1000>>
+				[[Implement|edicts][$martialSchool = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsUpkeep += 1000, $slaveBaseMorale += 5]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -621,8 +621,8 @@
 	<<if $arcologies[0].FSRestart >= 40>>
 		<<if $eliteOfficers == 0>>
 			<br>''@@.lime;Elite officers:@@'' officers will be exclusively recruited from the elite of society.
-			<<if $authority >= 1000>>
-				[[Implement|edicts][$eliteOfficers = 1, cashX(-5000, "edicts"), $authority -= 1000, $militiaBaseMorale += 5, $slaveBaseMorale -= 5]]
+			<<if $SecExp.core.authority >= 1000>>
+				[[Implement|edicts][$eliteOfficers = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $militiaBaseMorale += 5, $slaveBaseMorale -= 5]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -633,8 +633,8 @@
 	<<if $arcologies[0].FSDegradationist >= 40>>
 		<<if $liveTargets == 0>>
 			<br>''@@.lime;Live targets drills:@@'' disobedient slaves will be used as live targets at shooting ranges.
-			<<if $authority >= 1000>>
-				[[Implement|edicts][$liveTargets = 1, cashX(-5000, "edicts"), $authority -= 1000]]
+			<<if $SecExp.core.authority >= 1000>>
+				[[Implement|edicts][$liveTargets = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -648,8 +648,8 @@
 	<<if $arcologies[0].FSRomanRevivalist >= 40 && $militiaFounded == 1>>
 		<<if $legionTradition == 0>>
 			<br>''@@.lime;Legionaries traditions:@@'' Fund specialized training for your recruits to turn them into the professional of Roman tradition.
-			<<if $authority >= 1000>>
-				[[Implement|edicts][$legionTradition = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsUpkeep += 1000, $militiaBaseDefense += 2, $militiaBaseMorale += 5, $militiaBaseHp++]]
+			<<if $SecExp.core.authority >= 1000>>
+				[[Implement|edicts][$legionTradition = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsUpkeep += 1000, $militiaBaseDefense += 2, $militiaBaseMorale += 5, $militiaBaseHp++]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -660,8 +660,8 @@
 	<<if $arcologies[0].FSEgyptianRevivalist >= 40 && $militiaFounded == 1>>
 		<<if $pharaonTradition == 0>>
 			<br>''@@.lime;Pharaonic traditions:@@'' Fund specialized training for your recruits to turn them into an army worthy of a pharaoh.
-			<<if $authority >= 1000>>
-				[[Implement|edicts][$pharaonTradition = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsUpkeep += 1000, $militiaBaseAttack += 2, $militiaBaseDefense += 2, $militiaBaseMorale += 10]]
+			<<if $SecExp.core.authority >= 1000>>
+				[[Implement|edicts][$pharaonTradition = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsUpkeep += 1000, $militiaBaseAttack += 2, $militiaBaseDefense += 2, $militiaBaseMorale += 10]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -672,8 +672,8 @@
 	<<if $arcologies[0].FSAztecRevivalist >= 40 && $mercenaries > 0>>
 		<<if $eagleWarriors == 0>>
 			<br>''@@.lime;Eagle warriors traditions:@@'' Fund specialized training for your mercenaries to turn them into the elite units of Aztec tradition.
-			<<if $authority >= 1000>>
-				[[Implement|edicts][$eagleWarriors = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsUpkeep += 1000, $mercBaseAttack += 4, $mercBaseDefense -= 2, $mercBaseMorale += 10]]
+			<<if $SecExp.core.authority >= 1000>>
+				[[Implement|edicts][$eagleWarriors = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsUpkeep += 1000, $mercBaseAttack += 4, $mercBaseDefense -= 2, $mercBaseMorale += 10]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -684,8 +684,8 @@
 	<<if $arcologies[0].FSEdoRevivalist >= 40 && $mercenaries > 0>>
 		<<if $ronin == 0>>
 			<br>''@@.lime;Ronin traditions:@@'' Fund specialized training for your mercenaries to turn them into the errant samurai of Japanese tradition.
-			<<if $authority >= 1000>>
-				[[Implement|edicts][$ronin = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsUpkeep += 1000, $mercBaseAttack += 2, $mercBaseDefense += 2, $mercBaseMorale += 10]]
+			<<if $SecExp.core.authority >= 1000>>
+				[[Implement|edicts][$ronin = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsUpkeep += 1000, $mercBaseAttack += 2, $mercBaseDefense += 2, $mercBaseMorale += 10]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -696,8 +696,8 @@
 	<<if $arcologies[0].FSArabianRevivalist >= 40>>
 		<<if $mamluks == 0>>
 			<br>''@@.lime;Mamluks traditions:@@'' Fund specialized training for your slaves to turn them into the mamluks slave soldiers of Arabian tradition.
-			<<if $authority >= 1000>>
-				[[Implement|edicts][$mamluks = 1, cashX(-5000, "edicts"), $authority -= 1000, $edictsUpkeep += 1000, $slaveBaseAttack += 2, $slaveBaseHp++, $slaveBaseMorale += 10]]
+			<<if $SecExp.core.authority >= 1000>>
+				[[Implement|edicts][$mamluks = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $edictsUpkeep += 1000, $slaveBaseAttack += 2, $slaveBaseHp++, $slaveBaseMorale += 10]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
@@ -708,8 +708,8 @@
 	<<if $arcologies[0].FSChineseRevivalist >= 40>>
 		<<if $sunTzu == 0>>
 			<br>''@@.lime;Sun Tzu Teachings:@@'' Fund specialized training for your units and officers to conform your army to the teachings of the "Art of War".
-			<<if $authority >= 1000>>
-				[[Implement|edicts][$sunTzu = 1, cashX(-5000, "edicts"), $authority -= 1000, $militiaBaseAttack++, $militiaBaseDefense++, $mercBaseAttack++, $mercBaseDefense++, $slaveBaseAttack++, $slaveBaseDefense++, $militiaBaseMorale += 5, $mercBaseMorale += 5, $slaveBaseMorale += 5, $edictsUpkeep += 1000]]
+			<<if $SecExp.core.authority >= 1000>>
+				[[Implement|edicts][$sunTzu = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000, $militiaBaseAttack++, $militiaBaseDefense++, $mercBaseAttack++, $mercBaseDefense++, $slaveBaseAttack++, $slaveBaseDefense++, $militiaBaseMorale += 5, $mercBaseMorale += 5, $slaveBaseMorale += 5, $edictsUpkeep += 1000]]
 			<<else>>
 				<br>//Not enough Authority.//
 			<</if>>
diff --git a/src/SecExp/proclamations.tw b/src/SecExp/proclamations.tw
index 2647c0801d7..74cd9c79f97 100644
--- a/src/SecExp/proclamations.tw
+++ b/src/SecExp/proclamations.tw
@@ -5,7 +5,7 @@
 You can dedicate the week to issue a proclamation, a powerful tool that will have an immediate noticeable effect on the arcology.
 You will use <<print $proclamationCurrency>> to enact it<<if $proclamationType != "none">> and will be about $proclamationType.<<else>>.<</if>>
 <br>
-<<if $authority >= 2000>>
+<<if $SecExp.core.authority >= 2000>>
 	<<link "Use authority" "proclamations">>
 		<<set $proclamationCurrency = "authority">>
 	<</link>>
diff --git a/src/SecExp/rebellionGenerator.tw b/src/SecExp/rebellionGenerator.tw
index 20788004074..fc366e9771f 100644
--- a/src/SecExp/rebellionGenerator.tw
+++ b/src/SecExp/rebellionGenerator.tw
@@ -5,22 +5,22 @@
 <<set _CSratio = $ACitizens / ($ASlaves)>>
 
 <strong>Slaves security analysis:</strong>
-<<if $authority <= 3000>>
+<<if $SecExp.core.authority <= 3000>>
 	Your very low authority allows slaves to think too freely.
 	<<set _slave += 30>>
-<<elseif $authority <= 6000>>
+<<elseif $SecExp.core.authority <= 6000>>
 	Your low authority allows slaves to think too freely.
 	<<set _slave += 25>>
-<<elseif $authority <= 9000>>
+<<elseif $SecExp.core.authority <= 9000>>
 	Your moderate authority allows slaves to think a bit too freely.
 	<<set _slave += 20>>
-<<elseif $authority <= 12000>>
+<<elseif $SecExp.core.authority <= 12000>>
 	Your good authority does not allow slaves to think too freely.
 	<<set _slave += 15>>
-<<elseif $authority <= 15000>>
+<<elseif $SecExp.core.authority <= 15000>>
 	Your high authority does not allow slaves to think too freely.
 	<<set _slave += 10>>
-<<elseif $authority <= 18000>>
+<<elseif $SecExp.core.authority <= 18000>>
 	Your very high authority does not allow slaves to think too freely.
 	<<set _slave += 5>>
 <<else>>
@@ -49,16 +49,16 @@
 	Citizen and slave populations are sufficiently balanced not to cause problems either way.
 	<<set _slave -= 1>>
 <</if>>
-<<if $security <= 10>>
+<<if $SecExp.security.cap <= 10>>
 	The very low security of the arcology leaves free space for slaves to organize and agitate.
 	<<set _slave += 30>>
-<<elseif $security <= 30>>
+<<elseif $SecExp.security.cap <= 30>>
 	The low security of the arcology leaves free space for slaves to organize and agitate.
 	<<set _slave += 20>>
-<<elseif $security <= 60>>
+<<elseif $SecExp.security.cap <= 60>>
 	The moderate security of the arcology does not allow free space for slaves to organize and agitate.
 	<<set _slave += 10>>
-<<elseif $security >= 90>>
+<<elseif $SecExp.security.cap >= 90>>
 	The high security of the arcology does not allow free space for slaves to organize and agitate.
 	<<set _slave -= 5>>
 <<else>>
@@ -86,35 +86,35 @@
 <br>
 <br>
 <strong>Citizens security analysis:</strong>
-<<if $authority <= 3000>>
+<<if $SecExp.core.authority <= 3000>>
 	Your very low authority allows your citizens to think too freely.
 	<<set _citizen += 30>>
-<<elseif $authority <= 6000>>
+<<elseif $SecExp.core.authority <= 6000>>
 	Your very low authority allows your citizens to think too freely.
 	<<set _citizen += 25>>
-<<elseif $authority <= 9000>>
+<<elseif $SecExp.core.authority <= 9000>>
 	Your moderate authority allows your citizens to think a bit too freely.
 	<<set _citizen += 20>>
-<<elseif $authority <= 12000>>
+<<elseif $SecExp.core.authority <= 12000>>
 	Your good authority does not allow your citizens to think too freely.
 	<<set _citizen += 15>>
-<<elseif $authority <= 15000>>
+<<elseif $SecExp.core.authority <= 15000>>
 	Your high authority does not allow your citizens to think too freely.
 	<<set _citizen += 10>>
-<<elseif $authority <= 18000>>
+<<elseif $SecExp.core.authority <= 18000>>
 	Your very high authority does not allow your citizens to think too freely.
 	<<set _citizen += 5>>
 <<else>>
 	Your absolute authority does not allow your citizens to have a single free thought.
 	<<set _citizen += 1>>
 <</if>>
-<<if $crime >= 90>>
+<<if $SecExp.core.crimeLow >= 90>>
 	The very high crime level of the arcology breeds extreme discontent between your citizens.
 	<<set _citizen += 30>>
-<<elseif $crime >= 60>>
+<<elseif $SecExp.core.crimeLow >= 60>>
 	The high crime level of the arcology breeds high discontent between your citizens.
 	<<set _citizen += 15>>
-<<elseif $crime >= 30>>
+<<elseif $SecExp.core.crimeLow >= 30>>
 	The low crime level of the arcology leaves your citizens happy and satisfied.
 	<<set _citizen += 5>>
 <<else>>
@@ -302,7 +302,7 @@
 		<<set $hasRebelledOnce = 1>>
 	<</if>>
 	/* calc how many slaves and citizens participate */
-	<<set _authFactor = Math.clamp(1 - ($authority / 20000),0.4,0.6)>>
+	<<set _authFactor = Math.clamp(1 - ($SecExp.core.authority / 20000),0.4,0.6)>>
 	<<set _repFactor = Math.clamp($rep / 20000,0.4,0.6)>>
 	<<set _rebelPercent = 0.3 * _authFactor>>
 	<<set _irregularPercent = 0.2 * _repFactor>>
@@ -372,7 +372,7 @@
 	<</if>>
 	<<set $leadingTroops = "assistant">>
 	/* calc how many citizens participate */
-	<<set _authFactor = Math.clamp(1 - ($authority / 20000),0.4,0.6)>>
+	<<set _authFactor = Math.clamp(1 - ($SecExp.core.authority / 20000),0.4,0.6)>>
 	<<set _repFactor = Math.clamp($rep / 20000,0.4,0.6)>>
 	<<set _rebelPercent = 0.3 * _authFactor>>
 	<<set _irregularPercent = 0.2 * _repFactor>>
diff --git a/src/SecExp/rebellionReport.tw b/src/SecExp/rebellionReport.tw
index ab79b6fa070..2c742d715bc 100644
--- a/src/SecExp/rebellionReport.tw
+++ b/src/SecExp/rebellionReport.tw
@@ -2,7 +2,7 @@
 
 <<set $nextButton = "Continue", $nextLink = "Scheduled Event", $showEncyclopedia = 1, $encyclopedia = "Battles">>
 <<set _oldRep = $rep>>
-<<set _oldAuth = $authority>>
+<<set _oldAuth = $SecExp.core.authority>>
 <<set $enemyLosses = Math.trunc($enemyLosses)>>
 <<if $enemyLosses > $attackTroops>>
 	<<set $enemyLosses = $attackTroops>>
@@ -123,13 +123,13 @@
 	<<if $battleResult == 3>>
 		Thanks to your victory, your @@.green;reputation@@ and @@.darkviolet;authority@@ increased.
 		<<run repX(random(800,1000), "war")>>
-		<<set $authority += random(800,1000)>>
+		<<set $SecExp.core.authority += random(800,1000)>>
 		<br>Many of the rebelling slaves were recaptured and punished. The instigators were executed one after another in a public trial that lasted for almost three days.
 		<<set $NPCSlaves -= random(10,30)>>
 	<<elseif $battleResult == -3>>
 		Due to your defeat, your @@.red;reputation@@ and @@.red;authority@@ decreased.
 		<<run repX(random(-800,-1000), "war")>>
-		<<set $authority -= random(800,1000)>>
+		<<set $SecExp.core.authority -= random(800,1000)>>
 		<br>After the battle most of the rebelling slaves managed to escape, while others remained in the arcology for days looting and hunting their former masters. The arcology will bear the scars of this day for a long time.
 		<<set $lowerClass -= random(50,100)>>
 		<<set _lostSlaves = Math.trunc(($attackTroops - $enemyLosses) * 0.8),
@@ -141,7 +141,7 @@
 	<<elseif $battleResult == -2>>
 		Due to your defeat, your @@.red;reputation@@ and @@.red;authority@@ decreased.
 		<<run repX(random(-600,-800), "war")>>
-		<<set $authority -= random(600,800)>>
+		<<set $SecExp.core.authority -= random(600,800)>>
 		<br>After the battle most of the rebelling slaves managed to escape, while others remained in the arcology for days looting and hunting their former masters. The arcology will bear the scars of this day for a long time.
 		<<set $lowerClass -= random(40,80)>>
 		<<set _lostSlaves = Math.trunc(($attackTroops - $enemyLosses) * 0.8),
@@ -153,13 +153,13 @@
 	<<elseif $battleResult == 2>>
 		Thanks to your victory, your @@.green;reputation@@ and @@.darkviolet;authority@@ increased.
 		<<run repX(random(600,180), "war")>>
-		<<set $authority += random(600,800)>>
+		<<set $SecExp.core.authority += random(600,800)>>
 		<br>Many of the rebelling slaves were recaptured and punished. The instigators were executed one after another in a public trial that lasted for almost three days.
 		<<set $NPCSlaves -= random(10,30)>>
 	<<elseif $battleResult == -1>>
 		Rather than waste the lives of your men you decided to surrender, hoping the rebels will cause less damage if you indulge them, this is however a big hit to your status. Your @@.red;reputation@@ and @@.red;authority@@ are significantly impacted.
 		<<run repX(random(-1000,-1200), "war")>>
-		<<set $authority -= random(1000,1200)>>
+		<<set $SecExp.core.authority -= random(1000,1200)>>
 		<br>
 		The surrender allows the arcology to survive @@.yellow;mostly intact,@@ however reports of @@.red;mass looting and killing of citizens@@ flood your office for a few days.
 		<<run cashX(-1000, "war")>>
@@ -255,20 +255,20 @@
 	<<if $battleResult == 3>>
 		Thanks to your victory, your @@.green;reputation@@ and @@.darkviolet;authority@@ increased.
 		<<run repX(random(800,1000), "war")>>
-		<<set $authority += random(800,1000)>>
+		<<set $SecExp.core.authority += random(800,1000)>>
 		<br>Many of the rebelling citizens were captured and punished, many others enslaved. The instigators were executed one after another in a public trial that lasted for almost three days.
 		<<set $lowerClass -= random(10,30)>>
 	<<elseif $battleResult == -3>>
 		Due to your defeat, your @@.red;reputation@@ and @@.red;authority@@ decreased.
 		<<run repX(random(-800,-1000), "war")>>
-		<<set $authority -= random(800,1000)>>
+		<<set $SecExp.core.authority -= random(800,1000)>>
 		<br>After the battle most of the rebelling citizens remained in the arcology for days looting and hunting their former arcology. We will bear the scars of this day for a long time.
 		<<set $lowerClass -= Math.trunc(($attackTroops - $enemyLosses) * 0.8)>>
 		<<set $rebelDefeatAftermath = 5>>
 	<<elseif $battleResult == -2>>
 		Due to your defeat, your @@.red;reputation@@ and @@.red;authority@@ decreased.
 		<<run repX(random(-600,-800), "war")>>
-		<<set $authority -= random(600,800)>>
+		<<set $SecExp.core.authority -= random(600,800)>>
 		<br>After the battle most of the rebelling citizens remained in the arcology for days looting and hunting their former arcology. We will bear the scars of this day for a long time.
 		<<set $lowerClass -= random(40,80)>>
 		<<set _lostSlaves = Math.trunc(($attackTroops - $enemyLosses) * 0.6),
@@ -280,13 +280,13 @@
 	<<elseif $battleResult == 2>>
 		Thanks to your victory, your @@.green;reputation@@ and @@.darkviolet;authority@@ increased.
 		<<run repX(random(600,180), "war")>>
-		<<set $authority += random(600,800)>>
+		<<set $SecExp.core.authority += random(600,800)>>
 		<br>Many of the rebelling citizens were captured and punished, many others enslaved. The instigators were executed one after another in a public trial that lasted for almost three days.
 		<<set $NPCSlaves -= random(10,30)>>
 	<<elseif $battleResult == -1>>
 		Rather than waste the lives of your men you decided to surrender, hoping the rebels will cause less damage if you indulge them, this is however a big hit to your status. Your @@.red;reputation@@ and @@.red;authority@@ are significantly impacted.
 		<<run repX(random(-1000,-1200), "war")>>
-		<<set $authority -= random(1000,1200)>>
+		<<set $SecExp.core.authority -= random(1000,1200)>>
 		<br>
 		The surrender allows the arcology to survive @@.yellow;mostly intact,@@ however reports of @@.red;mass looting and killing of citizens@@ flood your office for a few days.
 		<<run cashX(-1000, "war")>>
diff --git a/src/SecExp/riotControlCenter.tw b/src/SecExp/riotControlCenter.tw
index 67948d1de74..b7df57ccd8e 100644
--- a/src/SecExp/riotControlCenter.tw
+++ b/src/SecExp/riotControlCenter.tw
@@ -110,7 +110,7 @@ The riot control center opens its guarded doors to you. The great chamber inside
 		<<if $sentUnitCooldown == 0>>
 			<br><<link "Deploy the unit against slaves rebel leaders">>
 				<<if $riotUpgrades.rapidUnitCost == 0>>
-					<<set $authority -= 1000 + 50 * $riotUpgrades.rapidUnit>>
+					<<set $SecExp.core.authority -= 1000 + 50 * $riotUpgrades.rapidUnit>>
 				<<else>>
 					<<run repX(forceNeg(1000 + 50 * $riotUpgrades.rapidUnit), "war")>>
 				<</if>>
@@ -124,7 +124,7 @@ The riot control center opens its guarded doors to you. The great chamber inside
 			<</link>>
 			<br><<link "Deploy the unit against citizens rebel leaders">>
 				<<if $riotUpgrades.rapidUnitCost == 0>>
-					<<set $authority -= 1000 + 50 * $riotUpgrades.rapidUnit>>
+					<<set $SecExp.core.authority -= 1000 + 50 * $riotUpgrades.rapidUnit>>
 				<<else>>
 					<<run repX(forceNeg(1000 + 50 * $riotUpgrades.rapidUnit), "war")>>
 				<</if>>
diff --git a/src/SecExp/secExp.js b/src/SecExp/secExp.js
new file mode 100755
index 00000000000..05c2a8b452c
--- /dev/null
+++ b/src/SecExp/secExp.js
@@ -0,0 +1,3749 @@
+// V = SugarCube.State.variables, T = SugarCube.State.temporary;
+// App.SecExp.Check.gen()- > conflcitOptions -> conflcitHandler -> conflcitReport -> Scheduled Event
+App.SecExp.Check = (function() {
+	return {
+		general:general,
+		/* secRestPoint:secRestPoint,
+		crimeCap:crimeCap,
+		reqMenials:reqMenials,
+		initialTrade:initialTrade,
+		troopCount:troopCount,
+		edictsUpkeep:edictsUpkeep,
+		fixBrokenStats:fixBrokenStats,
+		baseStats:baseStats,
+		units:units,
+		// fixBrokenUnits:fixBrokenUnits,
+		gen:Generator, */
+	};
+
+	function general() {
+		const V = State.variables, baseReleaseID = 1049;
+		/* function jsDel(input) {
+			for(let i = 0; i < input.length; i++) {
+				if(jsDef(input[i] === true)) {
+					delete input[i];
+				}
+			}
+		}*/
+
+		V.SecExp = V.SecExp || {};
+		/* V.SecExp.settings = V.SecExp.settings || {};
+		V.SecExp.settings.active = V.SecExp.settings.active || 0;
+		if (jsDef(V.secExp)) {
+			V.SecExp.settings.active = V.secExp; delete V.secExp;
+		}
+
+		V.SecExp.settings.show = V.SecExp.settings.show || 0;
+		if (jsDef(V.showSecExp)) {
+			V.SecExp.settings.show = V.showSecExp; delete V.showSecExp;
+		}
+
+		if (passage() === "init" || passage() === "New Game Plus") {
+			V.SecExp =
+			{
+				Active: V.SecExp.settings.active, show:V.SecExp.settings.show,
+			};
+		}
+		*/
+
+		// if (V.SecExp.settings.active > 0) {
+		 V.SecExp.core = V.SecExp.core || {};
+		 /* V.SecExp.army = V.SecExp.army || {};
+		 V.SecExp.army.units = V.SecExp.army.units || {};
+			V.SecExp.army.unitPool = ['Bots', 'Slaves', 'Militia', 'Mercs'];
+			V.SecExp.core.equipMod = 0.15;
+
+			V.SecExp.core.trade = V.SecExp.core.trade || 0;
+			if (jsDef(V.trade)) {
+				V.SecExp.core.trade = V.trade;
+			}
+			*/
+
+			V.SecExp.core.authority = V.SecExp.core.authority || 0;
+			if (jsDef(V.authority)) {
+				V.SecExp.core.authority = V.authority;
+			}
+
+			V.SecExp.security = V.SecExp.security || {};
+			V.SecExp.security.cap = V.SecExp.security.cap || 100;
+			if (jsDef(V.security)) {
+				V.SecExp.security.cap = V.security;
+			}
+			V.SecExp.security.low = V.SecExp.security.low || 40;
+			if (jsDef(V.secRestPoint)) {
+				V.SecExp.security.low = V.secRestPoint;
+			}
+
+			V.SecExp.core.crimeCap = V.SecExp.core.crimeCap || 100;
+			if (jsDef(V.crimeCap)) {
+				V.SecExp.core.crimeCap = V.crimeCap;
+			}
+			V.SecExp.core.crimeLow = V.SecExp.core.crimeLow || 30;
+			if (jsDef(V.crime)) {
+				V.SecExp.core.crimeLow = V.crime;
+			}
+
+			/* V.SecExp.core.upgradeUpkeep = V.SecExp.core.upgradeUpkeep || 40;
+			if(jsDef(V.upgradeUpkeep)) {
+				V.SecExp.core.upgradeUpkeep = V.upgradeUpkeep;
+			}
+
+			V.SecExp.settings.difficulty = V.SecExp.settings.difficulty || 1;
+			if (jsDef(V.difficulty)) {
+				V.SecExp.settings.difficulty = V.difficulty;
+			}
+
+			if (V.SF.Toggle && V.SF.Active >= 1) {
+				V.SecExp.army.sf = V.SecExp.army.sf || {};
+				
+				V.SecExp.army.sf.gear = V.SecExp.army.sf.gear || 0;
+				if (jsDef(V.SFGear)) {
+					V.SecExp.army.sf.gear = V.SFGear;
+				}
+				
+				V.SecExp.army.sf.supportLevel = V.SecExp.army.sf.supportLevel || 0;
+				if (jsDef(V.SFSupportLevel)) {
+					V.SecExp.army.sf.supportLevel = V.SFSupportLevel;
+				}
+				V.SecExp.army.sf.upkeep = V.SecExp.army.sf.upkeep || 0;
+				if (jsDef(V.SFSupportUpkeep)) {
+					V.SecExp.army.sf.upkeep = V.SFSupportUpkeep;
+				}
+			} else {
+				jsDel([V.SFGear, V.SFSupportLevel, V.SFSupportUpkeep, V.SavedSFI]);
+			}
+
+			if (V.PCWounded === 1 && V.PCWoundCooldown > 0) {
+				V.SecExp.pcWounded = V.PCWoundCooldown;
+			}
+
+			troop: {maxUnitSize:30},
+			upgradeUpkeep:40, baseUpkeep:V.facilityCost*5,
+
+					target:{unit:0, index:0}
+					troop: {count:0, maxUnitSize:30, leader:"none"}, count:0,
+
+							battle:{
+								oceanic:0
+								pc:{
+								thisWeek:0, lastWeeks:0,
+								army:{
+									active:0,
+								},
+								units:[],
+							}
+						};
+					}
+				};
+
+				battle:{
+					oceanic:V.battlesEnabledOceanic
+					active:V.activeUnits
+				}
+			
+			V.SecExp.army.max = V.SecExp.army.max || 6;
+			if(jsDef(V.maxTroops)) {
+				V.SecExp.army.max = V.maxTroops;
+			}
+			
+			V.SecExp.army.totalKills = V.SecExp.army.totalKills || 0;
+			if(jsDef(V.totalKills)) {
+				V.SecExp.army.totalKills = V.totalKills;
+			}
+
+			V.SecExp.settings.battle = V.SecExp.settings.battle || {};
+			V.SecExp.settings.battle.enabled = V.SecExp.settings.battle.enabled || 1;
+			if(jsDef(V.battlesEnabled)) {
+				V.SecExp.settings.battle.enabled = V.battlesEnabled;
+			}
+
+			if(V.SecExp.settings.battle.enabled > 0) {
+			 V.SecExp.battle = V.SecExp.battle || {major:{}};
+				
+				V.SecExp.battle.savedRoster = V.SecExp.battle.savedRoster || {};
+				V.SecExp.battle.savedRoster.leader = V.SecExp.battle.savedRoster.leader || "none";
+				if (jsDef(V.SavedLeader)) {
+					V.SecExp.battle.savedRoster.leader = V.SavedLeader;
+				}
+				if (jsDef(V.SavedSFI)) {
+					V.SecExp.battle.savedRoster.sfSupport = V.SavedSFI;
+				}
+				if (jsDef(V.lastSelection)) {
+					V.SecExp.battle.savedRoster.lastSelection = V.lastSelection;
+				}
+
+			 V.SecExp.settings.battle.major = V.SecExp.settings.battle.major || {};
+			 V.SecExp.settings.battle.frequency = V.SecExp.settings.battle.frequency || 1;
+				if(jsDef(V.battleFrequency)) {
+					V.SecExp.settings.battle.frequency = V.battleFrequency;
+				}
+				V.SecExp.settings.battle.force = V.SecExp.settings.battle.force || 1;
+				if(jsDef(V.forceBattle)) {
+					V.SecExp.settings.battle.force = V.forceBattle;
+				}
+				
+				V.SecExp.battle.readiness = V.SecExp.battle.readiness || 1;
+				if(jsDef(V.readiness)) {
+					V.SecExp.battle.readiness = V.readiness;
+				}
+				V.SecExp.battle.recon = V.SecExp.battle.recon || 0;
+				if(jsDef(V.recon)) {
+					V.SecExp.battle.recon = V.recon;
+				}
+				
+				V.SecExp.settings.battle.allowSlavePrestige = V.SecExp.settings.battle.allowSlavePrestige || 1;
+				if(jsDef(V.allowPrestigeFromBattles)) {
+					V.SecExp.settings.battle.allowSlavePrestige = V.allowPrestigeFromBattles;
+				}
+				V.SecExp.battle.slaveVictories = V.SecExp.battle.slaveVictories || [];
+				if(jsDef(V.slaveVictories)) {
+					V.SecExp.battle.slaveVictories = V.slaveVictories;
+				}
+
+				V.SecExp.settings.battle.major.enabled = V.SecExp.settings.battle.major.enabled || 1;
+				if(jsDef(V.majorBattlesEnabled)) {
+					V.SecExp.settings.battle.major.enabled = V.majorBattlesEnabled;
+				}
+
+				if(V.SecExp.settings.battle.major.enabled > 0) {
+					V.SecExp.settings.battle.major.gameOver = V.SecExp.settings.battle.major.gameOver || 1;
+					if(jsDef(V.majorBattleGameOver)) {
+						V.SecExp.settings.battle.major.gameOver = V.majorBattleGameOver;
+					}
+					V.SecExp.settings.battle.major.force = V.SecExp.settings.battle.major.force || 0;
+					if(jsDef(V.forceMajorBattle)) {
+						V.SecExp.settings.battle.major.force = V.forceMajorBattle;
+					}
+
+					V.SecExp.settings.battle.major.mult = V.SecExp.settings.battle.major.mult || 1;
+					if(jsDef(V.majorBattleMult)) {
+						V.SecExp.settings.battle.major.mult = V.majorBattleMult;
+					}
+				}
+
+				if (V.releaseID < baseReleaseID) {
+					V.SecExp.battle.count = 0;
+					V.SecExp.battle.major = 0;
+					let vars = ['hasFoughtOnce', 'battlesCount', 'hasFoughtMajorBattleOnce', 'majorBattlesCount'];
+					for(let i = 0; i < vars.length; i++) {
+						if(jsDef(V[vars[i]]) && V[vars[i]] > 0) {
+							V.SecExp.battle.count += V[vars[i]];
+							if(vars[i] === 'hasFoughtMajorBattleOnce' || vars[i] === 'majorBattlesCount') {
+								V.SecExp.battle.major += V[vars[i]];
+							}
+						}
+						delete V[vars[i]];
+					}
+					if(V.SecExp.battle.count === 0) {
+						delete V.SecExp.battle.count;
+					}
+					if(V.SecExp.battle.major === 0) {
+						delete V.SecExp.battle.major;
+					}
+				}
+
+				if (jsDef(V.PCvictories) && V.PCvictories > 0) {
+					V.SecExp.battle.victory = V.PCvictories;
+				}
+				if (jsDef(V.PCvictoryStreak) && V.PCvictoryStreak > 0) {
+					V.SecExp.battle.victoryStreak = V.PCvictoryStreak;
+				}
+
+				if (jsDef(V.PClosses) && V.PClosses > 0) {
+					V.SecExp.battle.defeat = V.PClosses;
+				}
+				if (jsDef(V.PClossStreak) && V.PClossStreak > 0) {
+					V.SecExp.battle.defeatStreak = V.PClossStreak;
+				}
+
+				if(jsDef(V.lastAttackWeeks) && V.lastAttackWeeks > 0) {
+					V.SecExp.battle.weeksSinceLast = V.lastAttackWeeks;
+				}
+
+				if (jsDef(V.secBots)) {
+					V.SecExp.army.units.Bots = {squads:[], createdUnits:1};
+					delete V.secBots.isDeployed;
+					if(V.secBots.active === 0) {
+						delete V.secBots.active;
+					}
+					delete V.secBotsCost;
+					V.secBots.platoonName = "1st security drone platoon";
+					V.SecExp.army.units.Bots.squads.push(V.secBots);
+				}
+
+				if(V.createdMilitiaUnits > 0) {
+					V.SecExp.army.units.Militia = {
+						total:V.militiaTotalManpower, free:V.militiaFreeManpower,
+						employed:V.militiaEmployedManpower,
+						casualties:V.militiaTotalCasualties,
+						createdUnits: V.createdMilitiaUnits, squads:[]
+					};
+					if (V.militiaUnits.length > 0) {
+						for (let i = 0; i < V.militiaUnits.length; i++) {
+							delete V.militiaUnits[i].isDeployed;
+							if(V.militiaUnits[i].active === 0) {
+								delete V.militiaUnits[i].active;
+							}
+							if(V.militiaUnits[i].cyber === 0) {
+								delete V.militiaUnits[i].cyber;
+							}
+							if(V.militiaUnits[i].medics === 0) {
+								delete V.militiaUnits[i].medics;
+							}
+							if(V.militiaUnits[i].SF === 0) {
+								delete V.militiaUnits[i].SF;
+							}
+							V.SecExp.army.units.Militia.squads.push(V.militiaUnits[i]);
+						}
+					}
+				}
+
+				if(V.createdSlavesUnits > 0) {
+					V.SecExp.army.units.Slaves = {
+						employed:V.slavesEmployedManpower,
+						casualties:V.slavesTotalCasualties,
+						createdUnits: V.createdSlavesUnits, squads:[]
+					};
+					if (V.slaveUnits.length > 0) {
+						for (let i = 0; i < V.slaveUnits.length; i++) {
+							delete V.slaveUnits[i].isDeployed;
+							if(V.slaveUnits[i].active === 0) {
+								delete V.slaveUnits[i].active;
+							}
+							if(V.slaveUnits[i].cyber === 0) {
+								delete V.slaveUnits[i].cyber;
+							}
+							if(V.slaveUnits[i].medics === 0) {
+								delete V.slaveUnits[i].medics;
+							}
+							if(V.slaveUnits[i].SF === 0) {
+								delete V.slaveUnits[i].SF;
+							}
+							V.SecExp.army.units.Slaves.squads.push(V.slaveUnits[i]);
+						}
+					}
+				}
+
+				if(V.createdMercUnits > 0) {
+					V.SecExp.army.units.Mercs = {
+						total:V.mercTotalManpower, free:V.mercFreeManpower,
+						employed:V.mercEmployedManpower,
+						loyalty:V.mercLoyalty,
+						casualties:V.mercTotalCasualties,
+						createdUnits: V.createdMercUnits, squads:[]
+					};
+					if (V.mercUnits.length > 0) {
+						for (let i = 0; i < V.mercUnits.length; i++) {
+							delete V.mercUnits[i].isDeployed;
+							if(V.mercUnits[i].active === 0) {
+								delete V.mercUnits[i].active;
+							}
+							if(V.mercUnits[i].cyber === 0) {
+								delete V.mercUnits[i].cyber;
+							}
+							if(V.mercUnits[i].medics === 0) {
+								delete V.mercUnits[i].medics;
+							}
+							if(V.mercUnits[i].SF === 0) {
+								delete V.mercUnits[i].SF;
+							}
+							V.SecExp.army.units.Mercs.squads.push(V.mercUnits[i]);
+						}
+					}
+				}
+			}
+			
+			V.SecExp.settings.rebellion = V.SecExp.settings.rebellion || {};
+			V.SecExp.settings.rebellion.enabled = V.SecExp.settings.rebellion.enabled || 1;
+			if (jsDef(V.rebellionsEnabled)) {
+				V.SecExp.settings.rebellion.enabled = V.rebellionsEnabled;
+			}
+
+			if (V.SecExp.settings.rebellion.enabled > 0) {
+			 V.SecExp.rebellion = V.SecExp.rebellion || {};
+				if(jsDef(V.lastRebellionWeeks) && V.lastRebellionWeeks > 0) {
+					V.SecExp.rebellion.weeksSinceLast = V.lastRebellionWeeks;
+				}
+
+				if(jsDef(V.PCrebWon) && V.PCrebWon > 0) {
+					V.SecExp.rebellion.victory = V.PCrebWon;
+				}
+				if(jsDef(V.PCrebLoss) && V.PCrebLoss > 0) {
+					V.SecExp.rebellion.defeat = V.PCrebLoss;
+				}
+
+				if (V.releaseID < baseReleaseID) {
+					V.SecExp.rebellion.count = 0;
+					let vars = ['hasRebelledOnce', 'rebellionsCount'];
+					for(let i = 0; i < vars.length; i++) {
+						if(jsDef(V[vars[i]]) && V[vars[i]] > 0) {
+							V.SecExp.rebellion.count += V[vars[i]];
+						}
+						delete V[vars[i]];
+					}
+					if(V.SecExp.rebellion.count === 0) {
+						delete V.SecExp.rebellion.count;
+					}
+				}
+
+				if(V.arcRepairTime > 0) {
+					V.SecExp.rebellion.arcRepairTime = V.arcRepairTime;
+				}
+
+				V.SecExp.rebellion.tension = V.SecExp.rebellion.tension || 0;
+				if(jsDef(V.tension)) {
+					V.SecExp.rebellion.tension = V.tension;
+				}
+
+				V.SecExp.rebellion.slave = V.SecExp.rebellion.slave || 0;
+				if(jsDef(V.slaveProgress)) {
+					V.SecExp.rebellion.slave = V.slaveProgress;
+				}
+				V.SecExp.rebellion.rabble = V.SecExp.rebellion.rabble || 0;
+				if(jsDef(V.citizenProgress)) {
+					V.SecExp.rebellion.rabble = V.citizenProgress;
+				}
+
+				V.SecExp.settings.rebellion.force = V.SecExp.settings.rebellion.force || 0;
+				if (jsDef(V.forceRebellion)) {
+					V.SecExp.settings.rebellion.force = V.forceRebellion;
+				}
+				V.SecExp.settings.rebellion.gameOver = V.SecExp.settings.rebellion.gameOver || 1;
+				if (jsDef(V.rebellionGameOver)) {
+					V.SecExp.settings.rebellion.gameOver = V.rebellionGameOver;
+				}
+
+				V.SecExp.settings.rebellion.speed = V.SecExp.settings.rebellion.speed || 1;
+				if (jsDef(V.rebellionSpeed)) {
+					V.SecExp.settings.rebellion.speed = V.rebellionSpeed;
+				}
+
+				V.SecExp.rebellion.garrison = V.SecExp.rebellion.garrison || {};
+				if (jsDef(V.garrison)) {
+					let vars = ['reactor', 'reactorTime', 'waterway', 'waterwayTime', 'assistant', 'assistantTime', 'penthouse'];
+					for(let i = 0; i < vars.length; i++) {
+						if(jsDef(V[vars[i]]) && V[vars[i]] > 0) {
+							V.SecExp.rebellion.garrison[vars[i]] = V[vars[i]];
+						}
+						delete V[vars[i]];
+					}
+				}
+			}
+			
+			if (V.SecExp.settings.battle.enabled + V.SecExp.settings.rebellion.enabled > 0) {
+				V.SecExp.settings.showStats = V.SecExp.settings.showStats || 0;
+				if(jsDef(V.showBattleStatistics)) {
+					V.SecExp.settings.showStats = V.showBattleStatistics;
+				}
+			}
+
+			let baseUpkeepInit = V.facilityCost*5;
+
+			V.SecExp.buildings = V.SecExp.buildings || {};
+			V.SecExp.buildings.pr = V.SecExp.buildings.pr || {};
+			V.SecExp.buildings.pr.active = V.SecExp.buildings.pr.active || 0;
+			if (jsDef(V.propHub)) {
+				V.SecExp.buildings.pr.active = V.propHub; delete V.propHub;
+			}
+
+			if(V.SecExp.buildings.pr.active > 0) {
+				V.SecExp.buildings.pr.upkeep = V.SecExp.buildings.pr.upkeep || baseUpkeepInit;
+				if (jsDef(V.propHubUpkeep)) {
+					V.SecExp.buildings.pr.upkeep = V.propHubUpkeep;
+				}
+
+				V.SecExp.buildings.pr.campaign = V.SecExp.buildings.pr.campaign || 0;
+				if (jsDef(V.propCampaign)) {
+					V.SecExp.buildings.pr.campaign = V.propCampaign;
+				}
+
+				V.SecExp.buildings.pr.miniTruth = V.SecExp.buildings.pr.miniTruth || 0;
+				if (jsDef(V.miniTruth)) {
+					V.SecExp.buildings.pr.miniTruth = V.miniTruth;
+				}
+
+				V.SecExp.buildings.pr.SS = V.SecExp.buildings.pr.SS || 0;
+				if (jsDef(V.secretService)) {
+					V.SecExp.buildings.pr.SS = V.secretService;
+				}
+
+				V.SecExp.buildings.pr.focus = V.SecExp.buildings.pr.focus || "none";
+				if (jsDef(V.propFocus)) {
+					V.SecExp.buildings.pr.focus = V.propFocus;
+				}
+
+				let vars = ['RecuriterOffice', 'fakeNews', 'controlLeaks', 'marketInfiltration', 'blackOps'];
+				for(let i = 0; i < vars.length; i++) {
+					if(jsDef(V[vars[i]]) && V[vars[i]] > 0) {
+						V.SecExp.buildings.pr[vars[i]] = V[vars[i]];
+					}
+					delete V[vars[i]];
+				}
+			}
+
+			V.SecExp.buildings.barracks = V.SecExp.buildings.barracks || {};
+			V.SecExp.buildings.barracks.active = V.SecExp.buildings.barracks.active || 0;
+			if (jsDef(V.secBarracks)) {
+				V.SecExp.buildings.barracks.active = V.secBarracks; delete V.secBarracks;
+			}
+
+			if (V.SecExp.buildings.barracks.active > 0) {
+				V.SecExp.buildings.barracks.upkeep = V.SecExp.buildings.barracks.upkeep || baseUpkeepInit;
+				if (jsDef(V.secBarracksUpkeep)) {
+					V.SecExp.buildings.barracks.upkeep = V.secBarracksUpkeep;
+				}
+
+				V.SecExp.buildings.barracks.upgrades = V.SecExp.buildings.barracks.upgrades || {};
+				V.SecExp.buildings.barracks.upgrades.size = V.SecExp.buildings.barracks.upgrades.size || 0;
+				V.SecExp.buildings.barracks.upgrades.luxury = V.SecExp.buildings.barracks.upgrades.luxury || 0;
+				V.SecExp.buildings.barracks.upgrades.training = V.SecExp.buildings.barracks.upgrades.training || 0;
+				V.SecExp.buildings.barracks.upgrades.loyaltyMod = V.SecExp.buildings.barracks.upgrades.loyaltyMod || 0;
+				if (jsDef(V.secBarracksUpgrades)) {
+					V.SecExp.buildings.barracks.upgrades = V.secBarracksUpgrades;
+				}
+			}
+
+			V.SecExp.security.hq = V.SecExp.security.hq || {};
+			V.SecExp.security.hq.active = V.SecExp.security.hq.active || 0;
+			if (jsDef(V.secHQ)) {
+				V.SecExp.security.hq.active = V.secHQ; delete V.secHQ;
+			}
+
+			if (V.SecExp.security.hq.active > 0) {
+				V.SecExp.security.hq.upkeep = V.SecExp.security.hq.upkeep || baseUpkeepInit;
+				if (jsDef(V.secHQUpkeep)) {
+					V.SecExp.security.hq.upkeep = V.secHQUpkeep;
+				}
+
+				V.SecExp.security.hq.menialsCount = V.SecExp.security.hq.menialsCount || 0;
+				if (jsDef(V.secMenials)) {
+					V.SecExp.security.hq.menialsCount = V.secMenials;
+				}
+				V.SecExp.security.hq.menialsReq = V.SecExp.security.hq.menialsReq || 20;
+				if (jsDef(V.reqMenials)) {
+					V.SecExp.security.hq.menialsReq = V.reqMenials;
+				}
+
+				V.SecExp.security.hq.upgrades = V.SecExp.security.hq.upgrades || {};
+
+				V.SecExp.security.hq.upgrades.coldstorage = V.SecExp.security.hq.upgrades.coldstorage || 0;
+				if (jsDef(V.secUpgrades.coldstorage)) {
+					V.SecExp.security.hq.upgrades.coldstorage = V.secUpgrades.coldstorage;
+				}
+
+				V.SecExp.security.hq.upgrades.internet = V.SecExp.security.hq.upgrades.internet || -1;
+				V.SecExp.security.hq.upgrades.crime = V.SecExp.security.hq.upgrades.crime || -1;
+				V.SecExp.security.hq.upgrades.intel = V.SecExp.security.hq.upgrades.intel || -1;
+				V.SecExp.security.hq.upgrades.readiness = V.SecExp.security.hq.upgrades.readiness || -1;
+
+				if (V.releaseID < baseReleaseID) {
+					const vars3 = ['nanoCams', 'cyberBots', 'eyeScan', 'cryptoAnalyzer'];
+						for (let i = 0; i < vars3.length; i++) {
+							if(V.secUpgrades[vars3[i]] === 1) {
+								V.SecExp.security.hq.upgrades.internet = vars3.indexOf(vars3[i]);
+							}
+							delete V.secUpgrades[vars3[i]];
+						}
+						const vars4 = ['autoTrial', 'autoArchive', 'worldProfiler', 'advForensic'];
+						for (let i = 0; i < vars4.length; i++) {
+							if(V.crimeUpgrades[vars4[i]] === 1) {
+								V.SecExp.security.hq.upgrades.crime = vars4.indexOf(vars4[i]);
+							}
+							delete V.crimeUpgrades[vars4[i]];
+						}
+
+						const vars5 = ['sensors', 'radar', 'signalIntercept'];
+						for (let i = 0; i < vars5.length; i++) {
+							if(V.intelUpgrades[vars5[i]] === 1) {
+								V.SecExp.security.hq.upgrades.intel = vars5.indexOf(vars5[i]);
+							}
+							delete V.intelUpgrades[vars5[i]];
+						}
+						const vars6 = ['earlyWarn', 'rapidPlatforms', 'pathways', 'rapidVehicles'];
+						for (let i = 0; i < vars6.length; i++) {
+							if(V.readinessUpgrades[vars6[i]] === 1) {
+								V.SecExp.security.hq.upgrades.readiness = vars6.indexOf(vars6[i]);
+							}
+							delete V.readinessUpgrades[vars6[i]];
+						}
+				}
+			}
+
+			V.SecExp.buildings.riotControl = V.SecExp.buildings.riotControl || {};
+			if (jsDef(V.riotCenter)) {
+				V.SecExp.buildings.riotControl.active = V.riotCenter; delete V.riotCenter;
+			} else {
+				V.SecExp.buildings.riotControl.active = V.SecExp.buildings.riotControl.active || 0;
+			}
+
+			if (V.SecExp.buildings.riotControl.active > 0) {
+				V.SecExp.buildings.riotControl.upkeep = V.SecExp.buildings.riotControl.upkeep || baseUpkeepInit;
+				if (jsDef(V.riotUpkeep)) {
+					V.SecExp.buildings.riotControl.upkeep = V.riotUpkeep;
+				}
+				V.SecExp.buildings.riotControl.upgrades = V.SecExp.buildings.riotControl.upgrades || {socity:{brainImplant:{}}, unit:{}};
+
+				if (jsDef(V.advancedRiotEquip) && V.advancedRiotEquip > 0) {
+					V.SecExp.buildings.riotControl.upgrades.unit.advancedEquip = V.advancedRiotEquip;
+				}
+
+				V.SecExp.buildings.riotControl.upgrades.unit.tier = V.SecExp.buildings.riotControl.upgrades.unit.tier || -4;
+				V.SecExp.buildings.riotControl.upgrades.unit.speed = V.SecExp.buildings.riotControl.upgrades.unit.speed || 0;
+				V.SecExp.buildings.riotControl.upgrades.socity.freeMedia = V.SecExp.buildings.riotControl.upgrades.socity.freeMedia || 0;
+
+				V.SecExp.buildings.riotControl.fort = V.SecExp.buildings.riotControl.fort || {};
+				V.SecExp.buildings.riotControl.fort.assistant = V.SecExp.buildings.riotControl.fort.assistant || 0;
+				V.SecExp.buildings.riotControl.fort.reactor = V.SecExp.buildings.riotControl.fort.reactor || 0;
+				V.SecExp.buildings.riotControl.fort.waterway = V.SecExp.buildings.riotControl.fort.waterway || 0;
+
+				if (jsDef(V.riotUpgrades)) {
+					V.SecExp.buildings.riotControl.upgrades.unit.tier += V.riotUpgrades.rapidUnit;
+					V.SecExp.buildings.riotControl.upgrades.unit.speed = V.riotUpgrades.rapidUnitSpeed;
+					V.SecExp.buildings.riotControl.upgrades.unit.cost = V.riotUpgrades.rapidUnitCost;
+					if(V.sentUnitCooldown > 0) {
+						V.SecExp.buildings.riotControl.upgrades.unit.cooldown = V.sentUnitCooldown;
+					}
+					V.SecExp.buildings.riotControl.upgrades.socity.freeMedia = V.riotUpgrades.freeMedia;
+					if(V.brainImplant > 0) {
+						V.SecExp.buildings.riotControl.upgrades.socity.brainImplant.resources = V.brainImplant;
+					}
+					if(V.brainImplantProject > 0 && V.brainImplant < 106) {
+						V.SecExp.buildings.riotControl.upgrades.socity.brainImplant.lv = V.brainImplantProject;
+					}
+					V.SecExp.buildings.riotControl.fort = V.fort;
+				}
+			}
+
+			V.SecExp.buildings.gunsSmith = V.SecExp.buildings.gunsSmith || {};
+			V.SecExp.buildings.gunsSmith.active = V.SecExp.buildings.gunsSmith.active || 0;
+			if (jsDef(V.weapManu)) {
+				V.SecExp.buildings.gunsSmith.active = V.weapManu; delete V.weapManu;
+			}
+
+			if (V.SecExp.buildings.gunsSmith.active > 0) {
+				V.SecExp.buildings.gunsSmith.productivity = V.SecExp.buildings.gunsSmith.productivity || 1;
+				if (jsDef(V.weapProductivity)) {
+					V.SecExp.buildings.gunsSmith.productivity = V.weapProductivity;
+				}
+				V.SecExp.buildings.gunsSmith.facilityLv = V.SecExp.buildings.gunsSmith.facilityLv || 1;
+				if (jsDef(V.weapLab)) {
+					V.SecExp.buildings.gunsSmith.facilityLv = V.weapLab;
+				}
+
+				V.SecExp.buildings.gunsSmith.sellTo = V.SecExp.buildings.gunsSmith.sellTo || {};
+				V.SecExp.buildings.gunsSmith.sellTo.citizen = V.SecExp.buildings.gunsSmith.sellTo.citizen || 1;
+				V.SecExp.buildings.gunsSmith.sellTo.raiders = V.SecExp.buildings.gunsSmith.sellTo.raiders || 1;
+				V.SecExp.buildings.gunsSmith.sellTo.oldWorld = V.SecExp.buildings.gunsSmith.sellTo.oldWorld || 1;
+				V.SecExp.buildings.gunsSmith.sellTo.FC = V.SecExp.buildings.gunsSmith.sellTo.FC || 1;
+				if (jsDef(V.sellTo)) {
+					V.SecExp.buildings.gunsSmith.sellTo = V.sellTo;
+				}
+				
+				V.SecExp.buildings.gunsSmith.workers = V.SecExp.buildings.gunsSmith.workers || {citizens:{count:0, wage:5000}};
+				V.SecExp.buildings.gunsSmith.workers.menials = V.SecExp.buildings.gunsSmith.workers.menials || 0;
+				if (V.weapMenials > 0) {
+					V.SecExp.buildings.gunsSmith.workers.menials = V.weapMenials;
+				}
+
+				V.SecExp.buildings.gunsSmith.upgrade = V.SecExp.buildings.gunsSmith.upgrade || {};
+
+				V.SecExp.buildings.gunsSmith.upgrade.baseTime = V.SecExp.buildings.gunsSmith.upgrade.baseTime || 10;
+				if (jsDef(V.baseUpgradeTime)) {
+					V.SecExp.buildings.gunsSmith.upgrade.baseTime = V.baseUpgradeTime;
+				}
+				V.SecExp.buildings.gunsSmith.upgrade.finished = V.SecExp.buildings.gunsSmith.upgrade.finished || [];
+				if (jsDef(V.completedUpgrades)) {
+					V.SecExp.buildings.gunsSmith.upgrade.finished = V.completedUpgrades;
+				}
+
+				V.SecExp.buildings.gunsSmith.upgrade.current = V.SecExp.buildings.gunsSmith.upgrade.current || {};
+				if (jsDef(V.currentUpgrade) && V.currentUpgrade.time > 0) {
+					V.SecExp.buildings.gunsSmith.upgrade.current = V.currentUpgrade;
+				}
+
+				V.SecExp.buildings.gunsSmith.upgrade.drone = V.SecExp.buildings.gunsSmith.upgrade.drone || {};
+				V.SecExp.buildings.gunsSmith.upgrade.drone.atk = V.SecExp.buildings.gunsSmith.upgrade.drone.atk || 0;
+				V.SecExp.buildings.gunsSmith.upgrade.drone.def = V.SecExp.buildings.gunsSmith.upgrade.drone.def || 0;
+				V.SecExp.buildings.gunsSmith.upgrade.drone.hp = V.SecExp.buildings.gunsSmith.upgrade.drone.hp || 0;
+				if (jsDef(V.droneUpgrades)) {
+					V.SecExp.buildings.gunsSmith.upgrade.drone.atk = V.droneUpgrades.attack;
+					V.SecExp.buildings.gunsSmith.upgrade.drone.def = V.droneUpgrades.defense;
+					V.SecExp.buildings.gunsSmith.upgrade.drone.hp = V.droneUpgrades.hp;
+				}
+
+				V.SecExp.buildings.gunsSmith.upgrade.human = V.SecExp.buildings.gunsSmith.upgrade.human || {};
+				V.SecExp.buildings.gunsSmith.upgrade.human.atk = V.SecExp.buildings.gunsSmith.upgrade.human.atk || 0;
+				V.SecExp.buildings.gunsSmith.upgrade.human.def = V.SecExp.buildings.gunsSmith.upgrade.human.def || 0;
+				V.SecExp.buildings.gunsSmith.upgrade.human.hp = V.SecExp.buildings.gunsSmith.upgrade.human.hp || 0;
+				V.SecExp.buildings.gunsSmith.upgrade.human.morale = V.SecExp.buildings.gunsSmith.upgrade.human.morale || 0;
+				if (jsDef(V.humanUpgrade)) {
+					V.SecExp.buildings.gunsSmith.upgrade.human.atk = V.humanUpgrade.attack;
+					V.SecExp.buildings.gunsSmith.upgrade.human.def = V.humanUpgrade.defense;
+					V.SecExp.buildings.gunsSmith.upgrade.human.hp = V.humanUpgrade.hp;
+					V.SecExp.buildings.gunsSmith.upgrade.human.morale = V.humanUpgrade.morale;
+				}
+			}
+
+			V.SecExp.smilingMan = V.SecExp.smilingMan || {};
+			V.SecExp.smilingMan.progress = V.SecExp.smilingMan.progress || 0;
+			if (jsDef(V.smilingManProgress)) {
+				V.SecExp.smilingMan.progress = V.smilingManProgress;
+				if(V.SecExp.smilingMan.progress < 4) {
+					V.SecExp.smilingMan.relationship = V.relationshipLM;
+					V.SecExp.smilingMan.investedFunds = V.investedFunds;
+				}
+				if (V.globalCrisisWeeks > 0) {
+					V.SecExp.smilingMan.globalCrisisWeeks = V.globalCrisisWeeks;
+				}
+				V.SecExp.smilingMan.fate = V.smilingManFate;
+			}
+
+			V.SecExp.buildings.hub = V.SecExp.buildings.hub || {};
+			V.SecExp.buildings.hub.active = V.SecExp.buildings.hub.active || 0;
+			if (jsDef(V.transportHub)) {
+				V.SecExp.buildings.hub.active = V.transportHub; delete V.transportHub;
+			}
+
+			if (V.SecExp.buildings.hub.active > 0) {
+				V.SecExp.buildings.hub.airport = V.SecExp.buildings.hub.airport || 1;
+				if (jsDef(V.airport)) {
+					V.SecExp.buildings.hub.airport = V.airport;
+				}
+				V.SecExp.buildings.hub.security = V.SecExp.buildings.hub.security || 1;
+				if (jsDef(V.hubSecurity)) {
+					V.SecExp.buildings.hub.security = V.hubSecurity;
+				}
+
+				if(V.terrain !== "oceanic" && V.terrain !== "marine") {
+					V.SecExp.buildings.hub.railway = V.SecExp.buildings.hub.railway || 1;
+					if (jsDef(V.railway)) {
+						V.SecExp.buildings.hub.railway = V.railway;
+					}
+				} else {
+					V.SecExp.buildings.hub.docks = V.SecExp.buildings.hub.docks || 1;
+					if (jsDef(V.docks)) {
+						V.SecExp.buildings.hub.docks = V.docks;
+					}
+				}
+			}
+
+			V.SecExp.edicts={};
+			V.SecExp.edicts.militiaLevel = V.SecExp.edicts.militiaLevel || -1;
+			V.SecExp.edicts.soldierWages = V.SecExp.edicts.soldierWages || 0;
+			V.SecExp.edicts.weaponsLaw = V.SecExp.edicts.weaponsLaw || 0;
+			if (V.releaseID < baseReleaseID) {
+				const vars = [
+					'edictsUpkeep', 'edictsAuthUpkeep',
+					'alternativeRents', 'enslavementRights', 'lowerRquirements',
+					'sellData', 'propCampaignBoost', 'weaponsLaw',
+					'limitImmigration', 'openBorders', 'soldierWages', 'slavesOfficers',
+					'martialSchool', 'discountMercenaries',
+
+					'militaryExemption', 'pregExemption', 'securityExemption',
+					'noSubhumansInArmy',
+
+					'slaveSoldierPrivilege', 'mercSoldierPrivilege', 'militiaSoldierPrivilege',
+
+					'tradeLegalAid', 'taxTrade',
+
+					'eliteOfficers', 'liveTargets', 'legionTradition', 'eagleWarriors',
+					'ronin', 'sunTzu', 'mamluks', 'pharaonTradition', 'subsidyChurch',
+					'slaveWatch'
+				];
+
+				const vars2 = ['militiaFounded', 'recruitVolunteers', 'conscription', 'militaryService', 'militarizedSociety'];
+					for (let i = 0; i < vars2.length; i++) {
+						if(V[vars2[i]] === 1) {
+							V.SecExp.edicts.militiaLevel = vars2.indexOf(vars2[i]);
+						}
+						delete V[vars2[i]];
+					}
+
+				for(let i = 0; i < vars.length; i++) {
+					if(jsDef(V[vars[i]])) {
+						if (vars[i] === 'soldierWages' || vars[i] === 'weaponsLaw') {
+							V.SecExp.edicts[vars[i]] = V[vars[i]];
+						} else if(V[vars[i]] > 0) {
+							if(vars[i] === 'edictsUpkeep') {
+								V.SecExp.edicts.upkeep = V[vars[i]];
+							} else {
+									V.SecExp.edicts[vars[i]] = V[vars[i]];
+							}
+						}
+						delete V[vars[i]];
+					}
+				}
+			}
+
+			V.SecExp.proclamation = V.SecExp.proclamation || {};
+			if (jsDef(V.proclamationsCooldown) && V.proclamationsCooldown > 0) {
+				V.SecExp.proclamation.cooldown = V.proclamationsCooldown;
+			}
+			V.SecExp.proclamation.currency = V.SecExp.proclamation.currency || "authority";
+			if (jsDef(V.proclamationCurrency)) {
+				V.SecExp.proclamation.currency = V.proclamationCurrency;
+			}
+			if (jsDef(V.proclamationType) && V.proclamationType !== "none") {
+				V.SecExp.proclamation.type = V.proclamationType;
+			}
+
+			// recalculation widgets
+			fixBrokenUnits();
+			fixBrokenStats();
+			recalcSecRestPoint();
+			recalcCrimeCap();
+			recalcReqMenials();
+			App.SecExp.Check.troopCount();
+			// r += `<recalcEdictsUpkeep) {`;
+			App.SecExp.Check.baseStats();
+			// recalcUnits();
+		}
+
+		if (V.releaseID < baseReleaseID) {
+			jsDel([V.proclamationsCooldown, V.proclamationCurrency, V.proclamationType]);
+			delete V.engageRule;
+
+			jsDel([V.secBotsBaseAttack, V.secBotsBaseDefense, V.secBotsMorale,
+				V.secBotsBaseHp]);
+
+			jsDel([V.militiaBaseAttack, V.militiaBaseDefense, V.militiaBaseMorale,
+				V.militiaBaseHp]);
+
+			delete V.riotUpkeep;
+			delete V.targetIndex; delete V.targetUnit;
+
+			delete V.lastRebellionWeeks;
+			delete V.PCrebWon; delete V.PCrebLoss;
+			delete V.rebellingUnits; delete V.rebellingMilitia;
+			delete V.rebellingSlaves; delete V.rebellingMercs;
+
+			delete V.totalKills;
+			delete V.maxTroops; delete V.soldierUpkeep;
+
+			delete V.arcRepairTime; delete V.repairTime;
+
+			delete V.tension;
+			delete V.hasRebelledOnce; delete V.rebellionsCount;
+			delete V.slaveRebellion; delete V.slaveProgress;
+			delete V.citizenRebellion; delete V.citizenProgress;
+
+			delete V.slaveBaseAttack;
+			delete V.slaveBaseDefense;
+			delete V.slaveBaseMorale;
+			delete V.slaveBaseHp;
+
+			delete V.mercBaseAttack;
+			delete V.mercBaseDefense;
+			delete V.mercBaseMorale;
+			delete V.mercBaseHp;
+
+			delete V.loyal;
+			delete V.rebelling;
+			delete V.slaveRebellionEventFires;
+			delete V.citizenRebellionEventFires;
+
+			delete V.irregulars;
+			delete V.troopCount;
+
+			delete V.hasFoughtOnce; delete V.battlesCount;
+			delete V.hasFoughtMajorBattleOnce; delete V.majorBattlesCount;
+			delete V.foughtThisWeek;
+			delete V.attackThisWeek;
+
+			delete V.equipMod;
+			delete V.sentUnitCooldown;
+
+			delete V.raBaseAttack;
+			delete V.raBaseDefense;
+			delete V.raBaseMorale;
+			delete V.raBaseHp;
+
+			delete V.fcBaseAttack;
+			delete V.fcBaseDefense;
+			delete V.fcBaseMorale;
+			delete V.fcBaseHp;
+
+			delete V.owBaseAttack;
+			delete V.owBaseDefense;
+			delete V.owBaseMorale;
+			delete V.owBaseHp;
+
+			delete V.ffBaseAttack;
+			delete V.ffBaseDefense;
+			delete V.ffBaseMorale;
+			delete V.ffBaseHp;
+
+			delete V.carriableSoldiers;
+			delete V.SFBaseAttack; delete V.SFatk;
+			delete V.SFBaseDefense; delete V.SFdef;
+			delete V.SFBaseMorale;
+			delete V.SFBaseHp; delete V.SFhp;
+
+			delete V.expectedEquip;
+			delete V.estimatedMen;
+			delete V.deployableUnits;
+			delete V.deployedUnits;
+			delete V.battleResult;
+
+			delete V.woundType;
+			delete V.maxTurns;
+			delete V.attackEquip;
+			delete V.enemyLosses;
+
+			delete V.attackTroops;
+			delete V.losses;
+			delete V.battleTurns;
+			delete V.SFIntervention;
+			delete V.battleTerrain;
+
+			delete V.tacticsSuccessful;
+			delete V.chosenTactic;
+			delete V.attackType;
+			delete V.leadingTroops;
+			delete V.gainedWarfare;
+
+			delete V.bribeCost;
+			delete V.baseBribePerAttacker;
+			delete V.slaveIncreasedPrestige;
+
+			delete V.difficulty;
+
+			delete V.saveValid;
+			delete V.SavedLeader;
+			delete V.SavedSFI;
+			delete V.lastSelection;
+			delete V.SFGear;
+
+			delete V.SFSupportLevel;
+			delete V.SFSupportUpkeep;
+			delete V.PCWounded;
+			delete V.PCWoundCooldown;
+			delete V.rebellionsEnabled;
+
+			delete V.forceRebellion;
+			delete V.rebellionGameOver;
+			delete V.rebellionSpeed;
+			delete V.garrison;
+
+			delete V.PCvictories;
+			delete V.PCvictoryStreak;
+			delete V.PClosses;
+			delete V.PClossStreak;
+
+			delete V.secBots.isDeployed;
+			delete V.secBots;
+			delete V.secBotsCost;
+			delete V.deployingBots;
+
+			delete V.militiaTotalManpower;
+			delete V.militiaFreeManpower;
+			delete V.militiaEmployedManpower;
+			delete V.militiaTotalCasualties;
+			delete V.createdMilitiaUnits;
+			delete V.militiaUnits;
+			delete V.deployingMilitia;
+
+			delete V.slavesEmployedManpower;
+			delete V.slavesTotalCasualties;
+			delete V.createdSlavesUnits;
+			delete V.slaveUnits;
+			delete V.deployingSlaves;
+
+			delete V.mercTotalManpower;
+			delete V.mercFreeManpower;
+			delete V.mercEmployedManpower;
+			delete V.mercLoyalty;
+			delete V.mercTotalCasualties;
+			delete V.createdMercUnits;
+			delete V.mercUnits;
+			delete V.deployingMercs;
+
+			jsDel([V.trade, V.authority, V.security, V.secRestPoint, V.crimeCap, V.crime,
+				V.wasToggledBefore]);
+			jsDel([V.readiness, V.recon, V.maxUnits, V.activeUnits,
+				V.lastAttackWeeks]);
+			jsDel([V.showBattleStatistics, V.forceBattle, V.battlesEnabled,
+				V.battlesEnabledOceanic]);
+				delete V.slaveVictories; delete V.allowPrestigeFromBattles;
+			jsDel([V.allowPrestigeFromBattles, V.battleFrequency, V.hasFoughtOnce]);
+			jsDel([V.majorBattlesEnabled, V.majorBattleGameOver,
+				V.hasFoughtMajorBattleOnce, V.majorBattle, V.forceMajorBattle, V.majorBattleMult]);
+
+			jsDel([V.propHubUpkeep, V.propCampaign, V.propFocus, V.miniTruth,
+				V.RecuriterOffice]);
+			jsDel([V.fakeNews, V.controlLeaks, V.secretService, V.blackOps,
+				V.marketInfiltration]);
+
+			jsDel([V.secBarracksUpkeep, V.secBarracksUpgrades]);
+
+			jsDel([V.secHQUpkeep, V.secMenials, V.reqMenials, V.secUpgrades,
+				V.crimeUpgrades]);
+			jsDel([V.intelUpgrades, V.readinessUpgrades]);
+
+			jsDel([V.advancedRiotEquip, V.riotUpkeep, V.fort, V.sentUnitCooldown,
+				V.riotUpgrades]);
+			jsDel([V.brainImplant, V.brainImplantProject]);
+
+			jsDel([V.weapProductivity, V.weapLab, V.weapHelots, V.sellTo]);
+			jsDel([V.baseUpgradeTime, V.completedUpgrades, V.droneUpgrades,
+				V.humanUpgrade, V.currentUpgrade, V.weapMenials]);
+
+			jsDel([V.smilingManProgress, V.investedFunds, V.relationshipLM,
+				V.captureRoute, V.collaborationRoute, V.smilingManWeek, V.globalCrisisWeeks,
+				V.smilingManFate]);
+
+			jsDel([V.airport, V.railway, V.docks, V.hubSecurity]);
+
+			// Unsed varabiles
+			delete V.rebelDefeatAftermath;	delete V.notInvolved;
+			delete V.limitSubhumans; delete V.oldFlux; */
+			V.releaseID = baseReleaseID;
+		// }
+	} // Closes general check funtion.
+
+	/* function secRestPoint() {
+		const V = State.variables;
+		let baseRest = 30;
+		if (V.SecExp.security.hq.upgrades.security >= 0) {
+			baseRest += 15;
+		}
+		if (V.SecExp.security.hq.upgrades.security >= 1) {
+			baseRest += 15;
+		}
+		if (V.SecExp.security.hq.upgrades.security >= 2) {
+			baseRest += 20;
+		}
+		if (V.SecExp.security.hq.upgrades.security >= 3) {
+			baseRest += 20;
+		}
+
+		V.SecExp.security.low = baseRest;
+	}
+
+	function crimeCap() {
+		const V = State.variables;
+		const baseCap = 100;
+		let newCap = baseCap;
+		if (V.SecExp.security.hq.upgrades.crime >= 0) {
+			newCap -= 10;
+		}
+		if (V.SecExp.security.hq.upgrades.crime >= 1) {
+			newCap -= 10;
+		}
+		if (V.SecExp.security.hq.upgrades.crime >= 2) {
+			newCap -= 15;
+		}
+		if (V.SecExp.security.hq.upgrades.crime >= 3) {
+			newCap -= 15;
+		}
+
+		V.SecExp.core.crimeCap = newCap;
+	}
+
+	function reqMenials() {
+		const V = State.variables;
+		let baseReq = 20;
+		if (V.SecExp.security.hq.upgrades.security >= 0) {
+			baseReq += 5;
+		}
+		if (V.SecExp.security.hq.upgrades.security >= 1) {
+			baseReq += 5;
+		}
+		if (V.SecExp.security.hq.upgrades.security >= 2) {
+			baseReq += 10;
+		}
+		if (V.SecExp.security.hq.upgrades.security === 3) {
+			baseReq += 10;
+		}
+
+		if (V.SecExp.security.hq.upgrades.crime >= 0) {
+			baseReq += 5;
+		}
+		if (V.SecExp.security.hq.upgrades.crime >= 1) {
+			baseReq += 5;
+		}
+		if (V.SecExp.security.hq.upgrades.crime >= 2) {
+			baseReq += 10;
+		}
+		if (V.SecExp.security.hq.upgrades.crime === 3) {
+			baseReq += 10;
+		}
+
+		if (V.SecExp.security.hq.upgrades.intel >= 0) {
+			baseReq += 5;
+		}
+		if (V.SecExp.security.hq.upgrades.intel >= 1) {
+			baseReq += 5;
+		}
+		if (V.SecExp.security.hq.upgrades.intel === 2) {
+			baseReq += 10;
+		}
+
+		if (V.SecExp.security.hq.upgrades.readiness >= 1) {
+			baseReq += 5;
+		}
+		if (V.SecExp.security.hq.upgrades.readiness >= 2) {
+			baseReq += 10;
+		}
+		if (V.SecExp.security.hq.upgrades.readiness === 3) {
+			baseReq += 10;
+		}
+		if (V.SecExp.security.hq.upgrades.coldstorage > 0) {
+			baseReq -= 10 * V.SecExp.security.hq.upgrades.coldstorage;
+		}
+
+		if (V.SecExp.army.sf.supportLevel  >= 1) {
+			baseReq -= 5 * V.SecExp.army.sf.supportLevel;
+		}
+
+		V.SecExp.security.hq.menialsReq = baseReq;
+	}
+
+	function initialTrade() {
+		const V = State.variables;
+		let initialTrade = jsRandom(20, 30);
+		if (V.terrain === "urban") {
+			initialTrade += jsRandom(10);
+		}
+		if (V.terrain === "ravine") {
+			initialTrade -= jsRandom(5);
+		}
+
+		if (["wealth", "capitalist", "celebrity", "BlackHat"].includes(V.PC.career)) {
+			initialTrade += jsRandom(5);
+		} else if (["escort", "servant", "gang"].includes(V.PC.career)) {
+			initialTrade -= jsRandom(5);
+		}
+
+		V.SecExp.core.trade = initialTrade;
+ }
+
+	function troopCount() {
+		const V = State.variables;
+		if(jsDef(V.SecExp.conflict) && jsDef(V.SecExp.conflict.type)) {
+		for (let i = 0; i < V.SecExp.army.unitPool.length; i++) {
+			if (jsDef(V.SecExp.army.units[V.SecExp.army.unitPool[i]]) && V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads.lenth > 0) {
+				for (let x = 0; x < V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads.lenth; x++) {
+					if (V.SecExp.conflict.type >= 2) {
+						if (jsDef(V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].isDeployed)) {
+							V.SecExp.conflict.army.troops += V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].troops;
+						}
+					} else {
+						if (jsDef(V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].active) && V.SecExp.conflict.loyal.includes(V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].name)) {
+							V.SecExp.conflict.army.troops += V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].troops;
+						}
+					}
+				}
+			}
+		}
+	}
+
+		if (input === 'manpower') {
+				if (V.mercenaries === 1) {
+					V.mercFreeManpower=jsRandom(5,20);
+				} else if (V.mercenaries > 1) {
+					V.mercFreeManpower=jsRandom(10,30);
+				}
+			function CorrectEmployedCount(target) {
+				let correctEmployedMP=0;
+				for (let i=0;i<V.target.length;i++) {
+					correctEmployedMP += V.target[i].troops;
+				}
+				var name=target;
+				name=name.replace('Units','');
+				name=nameEmployedManpower;
+				if (V.name !== correctEmployedMP) {
+					V.name=correctEmployedMP;
+				}
+			}
+			V.militiaTotalManpower=V.militiaEmployedManpower + V.militiaFreeManpower;
+			V.mercTotalManpower=V.mercEmployedManpower + V.mercFreeManpower;
+		}
+	}
+
+	function edictsUpkeep() { // recalcEdictsUpkeep
+		const V = State.variables;
+		let newAuthUpkeep = 0; // authority cost
+		let newUpkeep = 0; // cash cost
+
+		if (jsDef(V.SecExp.edicts.sellData)) {
+			newAuthUpkeep += 10;
+		}
+
+		if (jsDef(V.SecExp.edicts.slaveSoldierPrivilege)) {
+			newAuthUpkeep += 10;
+		}
+
+		if (V.SecExp.edicts.weaponsLaw === 0) {
+			newAuthUpkeep += 30;
+		} else if (V.SecExp.edicts.weaponsLaw === 2) {
+			newAuthUpkeep += 10;
+		} else if (V.SecExp.edicts.weaponsLaw === 1) {
+			newAuthUpkeep += 20;
+		}
+
+		if (jsDef(V.SecExp.edicts.slavesOfficers)) {
+			newAuthUpkeep += 10;
+		}
+
+		if (jsDef(V.SecExp.edicts.slaveWatch)) {
+			newUpkeep += 1000;
+		}
+
+		if (jsDef(V.SecExp.edicts.subsidyChurch)) {
+			newUpkeep += 1000;
+		}
+
+		if (jsDef(V.SecExp.edicts.martialSchool)) {
+			newUpkeep += 1000;
+		}
+
+		if (jsDef(V.SecExp.edicts.legionTradition)) {
+			newUpkeep += 1000;
+		}
+
+		if (jsDef(V.SecExp.edicts.pharaonTradition)) {
+			newUpkeep += 1000;
+		}
+
+		if (jsDef(V.SecExp.edicts.eagleWarriors)) {
+			newUpkeep += 1000;
+		}
+
+		if (jsDef(V.SecExp.edicts.ronin)) {
+			newUpkeep += 1000;
+		}
+
+		if (jsDef(V.mamluks)) {
+			newUpkeep += 1000;
+		}
+
+		if (jsDef(V.SecExp.edicts.sunTzu)) {
+			newUpkeep += 1000;
+		}
+
+		if (jsDef(V.SecExp.edicts.tradeLegalAid)) {
+			newUpkeep += 1000;
+		}
+
+		if(newUpkeep > 0) {
+			V.SecExp.edicts.upkeep = newUpkeep;
+		}
+		if(newAuthUpkeep > 0) {
+			V.SecExp.edicts.edictsAuthUpkeep = newAuthUpkeep;
+		}
+	}
+
+	function fixBrokenStats() {
+		const V = State.variables;
+		if (!isInt(V.SecExp.army.totalKills)) {
+			V.SecExp.army.totalKills = 0;
+		}
+		if (!isInt(V.SecExp.battle.count)) {
+			V.SecExp.battle.count = 0;
+		}
+
+		for  (let i = 0; i < V.SecExp.army.unitPool.length; i++) {
+			if (jsDef(V.SecExp.army.units[V.SecExp.army.unitPool[i]]) && V.SecExp.army.unitPool[i] !== "Bots") {
+				if(!isInt(V.SecExp.army.units[V.SecExp.army.unitPool[i]].casualties)) {
+					V.SecExp.army.units[V.SecExp.army.unitPool[i]].casualties = 0;
+				}
+				if(!isInt(V.SecExp.army.units[V.SecExp.army.unitPool[i]].employed)) {
+					V.SecExp.army.units[V.SecExp.army.unitPool[i]].employed = 0;
+				}
+
+				if(V.SecExp.army.unitPool[i] !== "Slaves") {
+					if(!isInt(V.SecExp.army.units[V.SecExp.army.unitPool[i]].free)) {
+						V.SecExp.army.units[V.SecExp.army.unitPool[i]].free = 0;
+					}
+					if(!isInt(V.SecExp.army.units[V.SecExp.army.unitPool[i]].total)) {
+						V.SecExp.army.units[V.SecExp.army.unitPool[i]].total = 0;
+					}
+				}
+			}
+		}
+	}
+
+	function baseStats() {
+		const V = State.variables;
+		for  (let i = 0; i < V.SecExp.army.unitPool.length; i++) {
+			if (jsDef(V.SecExp.army.units[V.SecExp.army.unitPool[i]])) {
+				V.SecExp.army.units[V.SecExp.army.unitPool[i]].base = V.SecExp.army.units[V.SecExp.army.unitPool[i]].base || {};
+				if (V.SecExp.army.units[V.SecExp.army.unitPool[i]] === 'Bots') {
+					if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.hp !== 3 + V.droneUpgrades.hp) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.hp = 3 + V.droneUpgrades.hp;
+						}
+				} else {
+					if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.hp !== 3 + V.humanUpgrade.hp) {
+						V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.hp = 3 + V.humanUpgrade.hp;
+					}
+				}
+				switch (V.SecExp.army.units[V.SecExp.army.unitPool[i]]) {
+					case 'Bots':
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.atk !== 7 + V.droneUpgrades.attack) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.atk = 7 + V.droneUpgrades.attack;
+						}
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.def !== 3 + V.droneUpgrades.defense) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.def = 3 + V.droneUpgrades.defense;
+						}
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.morale !== 200) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.morale = 200;
+						}
+						break;
+					case 'Militia':
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.atk !== 7 + V.humanUpgrade.attack) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.atk = 7 + V.humanUpgrade.attack;
+						}
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.def !== 5 + V.humanUpgrade.defense) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.def = 5 + V.humanUpgrade.defense;
+						}
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.morale !== 140) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.morale = 140;
+						}
+						break;
+					case 'Slaves':
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.atk !== 8 + V.humanUpgrade.attack) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.atk = 8 + V.humanUpgrade.attack;
+						}
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.def !== 5 + V.humanUpgrade.defense) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.def = 5 + V.humanUpgrade.defense;
+						}
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.morale !== 110) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.morale = 110;
+						}
+						break;
+					case 'Mercs':
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.atk !== 8 + V.humanUpgrade.attack) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.atk = 8 + V.humanUpgrade.attack;
+						}
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.def !== 4 + V.humanUpgrade.defense) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.def = 4 + V.humanUpgrade.defense;
+						}
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.morale !== 125) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.morale = 125;
+						}
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.hp !== 4 + V.humanUpgrade.hp) {
+							V.SecExp.army.units[V.SecExp.army.unitPool[i]].base.hp = 4 + V.humanUpgrade.hp;
+						}
+						break;
+				}
+			}
+		}
+	}
+
+	function units() { // recalcUnits
+		const V = State.variables;
+		V.maxUnits = 6 + V.SecExp.buildings.barracks.upgrades.size * 2;
+		V.activeUnits = V.militiaUnits.length + V.laveUnits.length + V.mercUnits.length;
+		if(V.readiness === 10) { V.maxUnits += 2; }
+	}
+
+	function fixBrokenUnits(input) { TODO: Sync with latest layout.
+		const V = State.variables;
+		let r='';
+		for (let i=0; i<input.length; i++) {
+			if (input[i] === 'secBots') {
+				if (jsDef(V.SecExpArmy.secBots.units.ID) === false) {
+								V.SecExpArmy.secBots.units.ID = -1;
+				}
+				if (!isInt(V.SecExpArmy.secBots.units.troops) ) {
+								r += `br>Fixed security bots wrong max troop count.`;
+								V.secBots.troops=V.SecExpArmy.secBots.units.troops;
+				}
+				if (V.SecExpArmy.secBots.units.troops > 0 && V.SecExpArmy.secBots.units.active !== 1) {
+								r += `br>Fixed security bots wrong 'active' flag.`;
+								V.SecExpArmy.secBots.units.active=1;
+				}
+			} else {
+				for (let i=0; i < input.length; i++) {
+					switch (input[i]) {
+						case 'militiaUnits':
+							input[i]=militiaUnits;
+							break;
+						case 'slaveUnits':
+							input[i]=slaveUnits;
+							break;
+						case 'mercUnits':
+							input[i]=mercUnits;
+							break;
+					}
+					let Currentvalue=V.input[i];
+					let name=input[i];
+					name=name.replace('Units', ' units');
+					if (jsDef(Currentvalue.SF) === false) {
+									r += `br>Set V.{name} missing 'SF' flag.`;
+									Currentvalue.SF=0;
+					}
+					if (jsDef(Currentvalue.ID) === false) {
+									r += `br>Set V.{name} missing ID.`;
+									generateUnitID(Currentvalue);
+					}
+					if ((Currentvalue.cyber) === false) {
+									r += `br>Set V.{name} missing 'cyber' flag.`;
+									Currentvalue.cyber=0;
+					}
+					if (jsDef(Currentvalue.commissars) === false) {
+									r += `br>Set V.{name} missing 'commissars' flag.`;
+									Currentvalue.commissars=0;
+					}
+					if (Currentvalue.maxTroops < 30) {
+								r += `br>Fixed V.{name} wrong max troop count.`;
+								Currentvalue.maxTroops = 30;
+					}
+					if (!isInt(Currentvalue.troops) ) {
+									r += `br>Fixed V.{name} unit wrong troop count.`;
+									Currentvalue.troops = Currentvalue.maxTroops;
+					}
+					if (Currentvalue.troops > 0 && Currentvalue.active !== 1) {
+									r += `br>Fixed V.{name} unit wrong 'active' flag.`;
+									Currentvalue.active = 1;
+					}
+				}
+			}
+		}
+		return r;
+	}
+
+	function Generator(mode = '') {
+		const V = State.variables;
+		 V.SecExp.conflict.type = 0 - 'slave rebellion'
+			V.SecExp.conflict.type = 1 - 'citizen rebellion'
+			V.SecExp.conflict.type = 2 - 'battle'
+			V.SecExp.conflict.type = 3 - 'major battle'
+		V.SecExp.conflict = {};
+		function eventObjectCreation(mode) {
+				Object.assign(
+				{
+					result:0,
+					attacker: {troops:0, losses:0, equip:0},
+					army:{losses:0, troops:0}
+				}, V.SecExp.conflict);
+
+				
+				if (V.SF.Toggle && V.SF.Active >= 1) {
+					V.SecExp.conflict.sf = {
+						base:{
+							attack:8 + V.humanUpgrade.attack,
+							defense:4 + V.humanUpgrade.defense,
+							morale:140 + V.humanUpgrade.morale,
+							hp:4 + V.humanUpgrade.hp
+						}
+					};
+
+					let upgradesSum;
+					upgradesSum = (V.SF.Squad.Armoury+V.SF.Squad.Drugs) + (V.SF.Squad.AA+V.SF.Squad.TA + V.SF.Squad.AV+V.SF.Squad.TV);
+					if (!isInt(upgradesSum) ) {
+							upgradesSum = jsRandom(10, 15);
+						}
+					if (jsDef(V.SecExp.conflict.type) && V.SecExp.conflict.type >= 2) {
+						V.SecExp.conflict.sf.atk = Math.trunc(0.65 * upgradesSum);
+						V.SecExp.conflict.sf.def=Math.trunc(0.40 * upgradesSum);
+
+						let carriableSoldiers = 125 * (V.SF.Squad.GunS + ((V.SF.Squad.AV + V.SF.Squad.TV)/2));
+						if (!isInt(carriableSoldiers) ) {
+							carriableSoldiers = Math.ceil(V.SF.Squad.Troops / 10);
+						}
+						if (V.SF.Squad.Troops > carriableSoldiers) {
+							carriableSoldiers = V.SF.Squad.Troops;
+						}
+
+						V.SecExp.conflict.sf.hp = carriableSoldiers * V.SecExp.conflict.sf.base.hp;
+						V.SecExp.conflict.army.troops += carriableSoldiers;
+					} else {
+						V.SecExp.conflict.sf.atk = Math.trunc(0.75 * upgradesSum);
+						V.SecExp.conflict.sf.def = Math.trunc(0.50 * upgradesSum);
+						// hp
+						V.SecExp.conflict.sf.hp = V.SF.Squad.Troops * V.SecExp.conflict.sf.base.hp;
+					}
+				}
+
+			if (mode === 'attack') {
+				V.SecExp.conflict.army.commander = "assistant";
+				Object.assign(
+				{
+					attackThisWeek:1, repairTime:3,
+					units:{deployed:0, deploying:{}, deployable:2 * V.SecExp.battle.readiness}
+				}, V.SecExp.conflict);
+				Object.assign(
+				{
+					base:{}, expectedEquip:0, estimatedMen:0, type:"none"
+				}, V.SecExp.conflict.attacker);
+			} else if (mode === 'rebellion') {
+				V.SecExp.conflict.engageRule = 0;
+				let weekMod = 0.50;
+				if (V.week <= 30) {
+					weekMod = 0.75 + (0.01+(V.week/200));
+				} else if (V.week <= 60) {
+					weekMod = 1 + (0.01+(V.week/300));
+				} else if (V.week <= 90) {
+					weekMod = 1.25 + (0.01+(V.week/400));
+				} else if (V.week <= 120) {
+					weekMod = 1.50 + (0.01+(V.week/500));
+				} else {
+					weekMod = 1.75;
+				}
+				const authFactor = Math.clamp(1 - (V.SecExp.core.authority / 20000), 0.4, 0.6);
+				const repFactor = Math.clamp(V.rep / 20000, 0.4, 0.6);
+				const rebelPercent = 0.3 * authFactor;
+				const irregularPercent = 0.2 * repFactor;
+				V.SecExp.conflict.attacker.troops += Math.clamp(Math.trunc(V.ASlaves * rebelPercent + jsRandom(-100, 100)) * weekMod, 50, V.ASlaves);
+				V.SecExp.conflict.irregulars = Math.clamp(Math.trunc(V.ACitizens * irregularPercent + jsRandom(-100, 100)) * weekMod, 50, V.ACitizens);
+				V.SecExp.conflict.army.troops += V.SecExp.conflict.irregulars;
+			}
+		}
+
+		if (mode === 'attack') {
+			let attackChance;
+			// attackChance value is the chance out of 100 of an attack happening this week
+			// attacks are deactivated if battles are not enabled, the arcology is in the middle of the ocean, security drones are not around yet, there is not a rebellion this week or the last attack/rebellion happened within 3 weeks
+			if (V.SecExp.settings.battle.enabled === 0 || (V.terrain === "oceanic" && V.battlesEnabledOceanic === 0) || V.arcologyUpgrade.drones !== 1 || jsDef(V.SecExp.battle.weeksSinceLast) && V.SecExp.battle.weeksSinceLast <= 3 || V.SecExp.settings.rebellion.enabled === 1 && (V.SecExp.conflict.type < 2 || jsDef(V.SecExp.rebellion.weeksSinceLast) && V.SecExp.rebellion.weeksSinceLast <= 3)) {
+				attackChance = 0;
+			} else {
+				if (V.week < 30) {
+					attackChance = 5;
+				} else if (V.week < 60) {
+					attackChance = 8;
+				} else if (V.week < 90) {
+					attackChance = 12;
+				} else if (V.week < 120) {
+					attackChance = 16;
+				} else {
+					attackChance = 20;
+				}
+				if (jsDef(V.SecExp.battle.count)) {
+					attackChance = 25;
+				}
+				if (jsDef(V.SecExp.battle.weeksSinceLast) && V.SecExp.battle.weeksSinceLast >= 10) {
+					attackChance += 5;
+				}
+			}
+
+			attackChance *= V.SecExp.settings.battle.frequency ; // battle frequency
+
+			if (V.forceBattle === 1 && V.SecExp.settings.rebellion.force !== 1 && jsDef(V.SecExp.conflict.occuredThisWeek) === false) {
+				attackChance = 100;
+			}
+
+			// Rolls to see if attack happens this week
+			// raiders are attracted by low security
+			// the old world by "degenerate" future societies
+			// free Cities by high prosperity
+			// freedom fighters by high slave/citizen ratio
+			if (jsRandom(1, 100) <= attackChance) {
+				eventObjectCreation(mode);
+				delete V.SecExp.battle.weeksSinceLast;
+				V.SecExp.conflict.army.chosenTactic = either("Bait and Bleed", "Blitzkrieg", "Choke Points", "Defense In Depth", "Guerrilla", "Human Wave", "Interior Lines", "Pincer Maneuver");
+				// type is the chance out of 100 of an attack of that type happening
+				let raider = 25;
+				let oldWorld = 25;
+				let freeCity = 25;
+				let free = 25;
+				// old world
+				if (V.arcologies[0].FSRomanRevivalist !== "unset" || V.arcologies[0].FSEdoRevivalist !== "unset" || V.arcologies[0].FSArabianRevivalist !== "unset" || V.arcologies[0].FSChineseRevivalist !== "unset" || V.arcologies[0].FSEgyptianRevivalist !== "unset" || V.arcologies[0].FSAztecRevivalist !== "unset" || V.arcologies[0].FSRepopulationFocus !== "unset" || V.arcologies[0].FSGenderRadicalist !== "unset" || V.arcologies[0].FSPastoralist !== "unset" || V.arcologies[0].FSChattelReligionist !== "unset") {
+					oldWorld += 15;
+					raider -= 5;
+					freeCity -= 5;
+					free -= 5;
+				} else if ( (V.arcologies[0].FSRomanRevivalist !== "unset" || V.arcologies[0].FSEdoRevivalist !== "unset" || V.arcologies[0].FSArabianRevivalist !== "unset" || V.arcologies[0].FSChineseRevivalist !== "unset" || V.arcologies[0].FSEgyptianRevivalist !== "unset" || V.arcologies[0].FSAztecRevivalist !== "unset") && (V.arcologies[0].FSRepopulationFocus !== "unset" || V.arcologies[0].FSGenderRadicalist !== "unset" || V.arcologies[0].FSPastoralist !== "unset" || V.arcologies[0].FSChattelReligionist !== "unset") ) {
+					oldWorld += 24;
+					raider -= 8;
+					freeCity -= 8;
+					free -= 8;
+				}
+				// freedom fighter
+				if (V.ASlaves > V.ACitizens * 2) {
+					oldWorld -= 8;
+					raider -= 8;
+					freeCity -= 8;
+					free += 24;
+				} else if (V.ASlaves > V.ACitizens * 1.2 || V.arcologies[0].FSDegradationist !== "unset") {
+					oldWorld -= 5;
+					raider -= 5;
+					freeCity -= 5;
+					free += 15;
+				}
+				// Free Cities
+				if (V.arcologies[0].prosperity >= 10 && V.arcologies[0].prosperity < 20) {
+					oldWorld -= 5;
+					raider -= 5;
+					freeCity += 15;
+					free -= 5;
+				} else if (V.arcologies[0].prosperity >= 20) {
+					oldWorld -= 8;
+					raider -= 8;
+					freeCity += 24;
+					free -= 8;
+				}
+				// raiders
+				if (V.SecExp.security.cap <= 50) {
+					oldWorld -= 5;
+					raider += 15;
+					freeCity -= 5;
+					free -= 5;
+				} else if (V.SecExp.security.cap <= 25) {
+					oldWorld -= 8;
+					raider += 24;
+					freeCity -= 8;
+					free -= 8;
+				}
+
+				// makes the actual roll
+				const attackerRoll = jsRandom(1, 100);
+				if (attackerRoll <= raider) {
+					V.SecExp.conflict.attacker.type = "raiders";
+				} else if ( attackerRoll <= raider + oldWorld) {
+					V.SecExp.conflict.attacker.type = "old world";
+				} else if ( attackerRoll <= raider + oldWorld + freeCity) {
+					V.SecExp.conflict.attacker.type = "free city";
+				} else if ( attackerRoll <= raider + oldWorld + freeCity + free) {
+					V.SecExp.conflict.attacker.type = "freedom fighters";
+				}
+			} else {
+				if(jsDef(V.SecExp.battle.weeksSinceLast)) {
+					V.SecExp.battle.weeksSinceLast++;
+				} else {
+					V.SecExp.battle.weeksSinceLast = 1;
+				}
+			}
+
+			// if an attack happens
+			if (V.SecExp.conflict.type >= 2) {
+				if (V.terrain === "urban") {
+					V.SecExp.conflict.terrain = either("outskirts", "urban", "wasteland");
+				} else if (V.terrain === "rural") {
+					V.SecExp.conflict.terrain = either("hills", "outskirts", "rural", "wasteland");
+				} else if (V.terrain === "ravine") {
+					V.SecExp.conflict.terrain = either("hills", "mountains", "outskirts", "wasteland");
+				} else if (V.terrain === "marine") {
+					V.SecExp.conflict.terrain = either("coast", "hills", "outskirts", "wasteland");
+				} else if (V.terrain === "oceanic") {
+					V.SecExp.conflict.terrain = either("coast", "hills", "outskirts", "wasteland");
+				} else {
+					V.SecExp.conflict.terrain = "error";
+				}
+
+				let L=0;
+				V.SecExp.conflict.attacker.base.hp = 2;
+
+				if (V.SecExp.conflict.attacker.type === "raiders") {
+					V.SecExp.conflict.attacker.troops = jsRandom(40, 80); L=1;
+
+					V.SecExp.conflict.attacker.base.attack = 7;
+					V.SecExp.conflict.attacker.base.defense = 2;
+					V.SecExp.conflict.attacker.base.morale = 100;
+				} else if (V.SecExp.conflict.attacker.type === "free city") {
+					V.SecExp.conflict.attacker.troops = jsRandom(20, 40);
+
+					V.SecExp.conflict.attacker.base.attack = 6;
+					V.SecExp.conflict.attacker.base.defense = 4;
+					V.SecExp.conflict.attacker.base.morale = 130;
+					V.SecExp.conflict.attacker.base.hp = 3;
+				} else if (V.SecExp.conflict.attacker.type === "old world") {
+					V.SecExp.conflict.attacker.troops = jsRandom(25, 50);
+
+					V.SecExp.conflict.attacker.base.attack = 8;
+					V.SecExp.conflict.attacker.base.defense = 4;
+					V.SecExp.conflict.attacker.base.morale = 110;
+				} else if (V.SecExp.conflict.attacker.type === "freedom fighters") {
+					V.SecExp.conflict.attacker.troops = jsRandom(30, 60);
+
+					V.SecExp.conflict.attacker.base.attack = 9;
+					V.SecExp.conflict.attacker.base.defense = 2;
+					V.SecExp.conflict.attacker.base.morale = 160;
+				}
+				if (V.week < 30) {
+					// V.SecExp.conflict.attacker.troops *= Math.trunc(jsRandom( (1*(1.01+(V.week/100))), (2*(1.01+(V.week/100))) ));
+					V.SecExp.conflict.attacker.troops *= jsRandom(1, 2);
+				} else if (V.week < 60) {
+					// V.SecExp.conflict.attacker.troops *= Math.trunc(jsRandom( (1*(1.01+(V.week/200))), (3*(1.01+(V.week/200))) ));
+					V.SecExp.conflict.attacker.troops *= jsRandom(1, 3);
+				} else if (V.week < 90) {
+					// V.SecExp.conflict.attacker.troops *= Math.trunc(jsRandom( (2*(1.01+(V.week/300))), (3*(1.01+(V.week/300))) ));
+					V.SecExp.conflict.attacker.troops *= jsRandom(2, 3);
+				} else if (V.week < 120) {
+					// V.SecExp.conflict.attacker.troops *= Math.trunc(jsRandom( (2*(1.01+(V.week/400))), (4*(1.01+(V.week/400))) ));
+					V.SecExp.conflict.attacker.troops *= jsRandom(2, 4);
+				} else {
+					V.SecExp.conflict.attacker.troops *= jsRandom(3, 5);
+				}
+				if (V.week < 60) {
+					V.SecExp.conflict.attacker.equip = jsRandom(0, 1);
+				} else if (V.week < 90) {
+					V.SecExp.conflict.attacker.equip = jsRandom(0, 3-L); // "raiders" V.SecExp.conflict.attacker.equip = jsRandom(0,2);
+				} else if (V.week < 120) {
+					V.SecExp.conflict.attacker.equip = jsRandom(1-L, 3); // "raiders" V.SecExp.conflict.attacker.equip = jsRandom(0,3);
+				} else {
+					V.SecExp.conflict.attacker.equip = jsRandom(2-L, 4-L); // "raiders" V.SecExp.conflict.attacker.equip = jsRandom(1,3);
+				}
+
+				if (V.SecExp.settings.battle.major.enabled === 1) { // major battles have a 50% chance of firing after week 120
+					if ((V.week >= 120 && V.SecExp.conflict.attacker.type !== "none" || V.SecExp.settings.battle.major.force > 0) && jsDef(V.SecExp.conflict.occuredThisWeek) === false) {
+						if (jsRandom(1, 100) >= 50 || V.SecExp.settings.battle.major.force > 0) {
+							V.SecExp.conflict.type = 3;
+							if (V.SF.Toggle && V.SF.Active >= 1) {
+								V.SecExp.army.sf.support.inBattle = 1;
+								V.SecExp.conflict.attacker.troops = Math.trunc(V.SecExp.conflict.attacker.troops * jsRandom(4, 6) * V.SecExp.settings.battle.major.mult);
+								V.SecExp.conflict.attacker.equip = either(3, 4);
+							} else {
+								V.SecExp.conflict.attacker.troops = Math.trunc(V.SecExp.conflict.attacker.troops * jsRandom(2, 3) * V.SecExp.settings.battle.major.mult);
+								V.SecExp.conflict.attacker.equip = either(2, 3, 4);
+							}
+						}
+					}
+				}
+
+				let bribe = 0;
+				if (V.week <= 30) {
+					bribe = 5000 + 5 * V.SecExp.conflict.attacker.troops;
+				} else if (V.week <= 30) {
+					bribe = 10000 + 5 * V.SecExp.conflict.attacker.troops;
+				} else if (V.week <= 30) {
+					bribe = 15000 + 5 * V.SecExp.conflict.attacker.troops;
+				} else if (V.week <= 30) {
+					bribe = 20000 + 5 * V.SecExp.conflict.attacker.troops;
+				} else if (V.week <= 30) {
+					bribe = 25000 + 5 * V.SecExp.conflict.attacker.troops;
+				}
+				if (V.SecExp.conflict.type === 3) {
+					bribe *= 3;
+				}
+				V.SecExp.conflict.bribe = Math.trunc(Math.clamp(V.SecExp.conflict.bribe,0 ,1000000));
+
+				V.SecExp.conflict.attacker.estimatedMen = Math.round(V.SecExp.conflict.attacker.troops * (1 + either(-1, 1) * (jsRandom(3, 4) - V.recon) * 0.1));
+				if (V.recon === 3) {
+					V.SecExp.conflict.attacker.expectedEquip = V.SecExp.conflict.attacker.equip + jsRandom(-1, 1);
+				} else if (V.recon === 2) {
+					V.SecExp.conflict.attacker.expectedEquip = V.SecExp.conflict.attacker.equip + jsRandom(-1, 2);
+				} else if (V.recon === 1) {
+					V.SecExp.conflict.attacker.expectedEquip = V.SecExp.conflict.attacker.equip + jsRandom(-2, 2);
+				} else {
+					V.SecExp.conflict.attacker.expectedEquip = V.SecExp.conflict.attacker.equip + jsRandom(-2, 3);
+				}
+			}
+		} else if (mode === 'rebellion') {
+			let r =``,
+			slave = 0,
+			citizen = 0,
+			CSratio = V.ACitizens / V.ASlaves;
+
+			r += `strong>Slaves security analysis:</strong>`;
+			if (V.SecExp.core.authority <= 3000) {
+				r += `Your very low authority allows slaves to think too freely.`;
+				slave += 30;
+			} else if (V.SecExp.core.authority <= 6000) {
+				r += `Your low authority allows slaves to think too freely.`;
+				slave += 25;
+			} else if (V.SecExp.core.authority <= 9000) {
+				r += `Your moderate authority allows slaves to think a bit too freely.`;
+				slave += 20;
+			} else if (V.SecExp.core.authority <= 12000) {
+				r += `Your good authority does not allow slaves to think too freely.`;
+				slave += 15;
+			} else if (V.SecExp.core.authority <= 15000) {
+				r += `Your high authority does not allow slaves to think too freely.`;
+				slave += 10;
+			} else if (V.SecExp.core.authority <= 18000) {
+				r += `Your very high authority does not allow slaves to think too freely.`;
+				slave += 5;
+			} else {
+				r += `Your absolute authority does not allow slaves to have a single free thought.`;
+				slave += 1;
+			}
+			if (CSratio <= 0.4) {
+				r += `There are a lot more slaves than citizens, making some doubt their masters are strong enough to stop them.`;
+				slave += 30;
+			} else if (CSratio <= 0.6) {
+				r += `There are a lot more slaves than citizens, making some doubt their masters are strong enough to stop them.`;
+				slave += 25;
+			} else if (CSratio <= 0.8) {
+				r += `There are more slaves than citizens, making some doubt their masters are strong enough to stop them.`;
+				slave += 20;
+			} else if (CSratio <= 1) {
+				r += `There are more slaves than citizens, making some doubt their masters are strong enough to stop them.`;
+				slave += 15;
+			} else if (CSratio <= 1.5) {
+				r += `There are fewer slaves than citizens, making some doubt they would be strong enough to defeat their masters.`;
+				slave += 10;
+			} else if (CSratio >= 3) {
+				r += `There are fewer slaves than citizens, making some doubt they would be strong enough to defeat their masters.`;
+				slave -= 5;
+			} else {
+				r += `Citizen and slave populations are sufficiently balanced not to cause problems either way.`;
+				slave -= 1;
+			}
+			if (V.SecExp.security.cap <= 10) {
+				r += `The very low security of the arcology leaves free space for slaves to organize and agitate.`;
+				slave += 30;
+			} else if (V.SecExp.security.cap <= 30) {
+				r += `The low security of the arcology leaves free space for slaves to organize and agitate.`;
+				slave += 20;
+			} else if (V.SecExp.security.cap <= 60) {
+				r += `The moderate security of the arcology does not allow free space for slaves to organize and agitate.`;
+				slave += 10;
+			} else if (V.SecExp.security.cap >= 90) {
+				r += `The high security of the arcology does not allow free space for slaves to organize and agitate.`;
+				slave -= 5;
+			} else {
+				r += `The high security of the arcology does not allow free space for slaves to organize and agitate.`;
+				slave -= 1;
+			}
+			if (V.arcologies[0].FSDegradationist !== "unset") {
+				r += `Many slaves are so disgusted by your degradationist society, that they are willing to rise up against their masters to escape.`;
+				slave += 30;
+			} else if (V.arcologies[0].FSPaternalist !== "unset") {
+			r += `	Many slaves are content to live in your paternalist society.`;
+				slave -= 5;
+			} else {
+				slave += 5;
+			}
+			if (V.arcologies[0].FSRestart !== "unset") {
+				r += `Many slaves are worried by your eugenics projects and some are pushed towards radicalization.`;
+				slave += 30;
+			} else if (V.arcologies[0].FSRepopulationFocus !== "unset") {
+				r += `Many slaves are pleasantly happy of your repopulation effort, affording them the freedom to reproduce.`;
+				slave -= 5;
+			} else {
+				slave += 5;
+			}
+			r += `\n\n`;
+			r += `<strong>Citizens security analysis:</strong>`;
+			if (V.SecExp.core.authority <= 3000) {
+				r += `Your very low authority allows your citizens to think too freely.`;
+				citizen += 30;
+			} else if (V.SecExp.core.authority <= 6000) {
+				r += `Your very low authority allows your citizens to think too freely.`;
+				citizen += 25;
+			} else if (V.SecExp.core.authority <= 9000) {
+				r += `Your moderate authority allows your citizens to think a bit too freely.`;
+				citizen += 20;
+			} else if (V.SecExp.core.authority <= 12000) {
+				r += `Your good authority does not allow your citizens to think too freely.`;
+				citizen += 15;
+			} else if (V.SecExp.core.authority <= 15000) {
+				r += `Your high authority does not allow your citizens to think too freely.`;
+				citizen += 10;
+			} else if (V.SecExp.core.authority <= 18000) {
+				r += `Your very high authority does not allow your citizens to think too freely.`;
+				citizen += 5;
+			} else {
+				r += `Your absolute authority does not allow your citizens to have a single free thought.`;
+				citizen += 1;
+			}
+			if (V.SecExp.core.crimeLow >= 90) {
+				r += `The very high crime level of the arcology breeds extreme discontent between your citizens.`;
+				citizen += 30;
+			} else if (V.SecExp.core.crimeLow >= 60) {
+				r += `The high crime level of the arcology breeds high discontent between your citizens.`;
+				citizen += 15;
+			} else if (V.SecExp.core.crimeLow >= 30) {
+				r += `The low crime level of the arcology leaves your citizens happy and satisfied.`;
+				citizen += 5;
+			} else {
+				r += `The very low crime level of the arcology leaves your citizens happy and satisfied.`;
+				citizen -= 5;
+			}
+			if (jsDef(V.SecExp.edicts.militiaFounded)) {
+				if (V.arcologies[0].FSRomanRevivalist === "unset" && V.arcologies[0].FSAztecRevivalist === "unset" && V.arcologies[0].FSEgyptianRevivalist === "unset" && V.arcologies[0].FSEdoRevivalist === "unset" && V.arcologies[0].FSArabianRevivalist === "unset" && V.arcologies[0].FSChineseRevivalist === "unset") {
+					if (V.SecExp.edicts.militiaLevel === 4) {
+						r += `Many of your citizens are offended by your extreme militarization of the arcology's society.`;
+						citizen += 20;
+					} else if (V.SecExp.edicts.militiaLevel === 3) {
+						r += `Many of your citizens are offended by your militarization of the arcology's society.`;
+						citizen += 15;
+					} else {
+						citizen += 10;
+					}
+				} else {
+					if (V.SecExp.edicts.militiaLevel === 4) {
+						r += `Some of your citizens are offended by your extreme militarization of the arcology's society.`;
+						citizen += 10;
+					} else if (V.SecExp.edicts.militiaLevel === 3) {
+						r += `Some of your citizens are offended by your militarization of the arcology's society.`;
+						citizen += 5;
+					} else {
+						citizen -= 5;
+					}
+				}
+			}
+			if (V.arcologies[0].FSNull !== "unset") {
+				r += `Many of your more conservative citizens do not enjoy the cultural freedom you afford the residents of the arcology.`;
+				citizen += either(20, 30);
+			}
+			if (V.arcologies[0].FSRestart !== "unset") {
+				if (CSratio > 2) {
+					r += `Your citizens are not happy with the noticeable lack of slaves compared to their numbers.`;
+					citizen += 20;
+				} else if (CSratio > 1) {
+					r += `Your citizens are not happy with the lack of slaves compared to their numbers.`;
+					citizen += 15;
+				} else if (CSratio < 0.5) {
+					citizen -= 5;
+				}
+			} else if (V.arcologies[0].FSRepopulationFocus !== "unset") {
+				if (CSratio < 0.5) {
+					r += `Your citizens are not happy about being outbred by the slaves of the arcology.`;
+					citizen += 20;
+				} else if (CSratio < 1) {
+					r += `Your citizens are not happy about being outbred by the slaves of the arcology.`;
+					citizen += 15;
+				} else if (CSratio > 1.4) {
+					citizen += 5;
+				}
+			}
+
+			// rolls to see if event happens
+			if (slave < 0) {
+				slave = 0;
+			} else if (slave >= 95) {
+				slave = 95;	// there's always a min 5% chance nothing happens
+			}
+			if (citizen < 0) {
+				citizen = 0;
+			} else if (citizen >= 95) {
+				citizen = 95;
+			}
+			const rebellionRoll = jsRandom(1, slave + citizen);
+			if (V.SecExp.buildings.riotControl.upgrades.socity.brainImplant.resources === 106) {
+				slave = Math.trunc(slave * 0.5 * V.SecExp.settings.rebellion.speed); citizen = Math.trunc(citizen * 0.5 * V.SecExp.settings.rebellion.speed);
+			} else {
+				slave = Math.trunc(slave * V.SecExp.settings.rebellion.speed); citizen = Math.trunc(citizen * V.SecExp.settings.rebellion.speed);
+			}
+
+			if (rebellionRoll <= slave) {
+				if (jsRandom(1, 100) < slave) {
+					V.SecExp.conflict.rebellionEvents = "slave";
+					if (V.SecExp.rebellion.tension !== 0) {
+						V.SecExp.rebellion.slave += Math.trunc(jsRandom(1, 5) * (V.SecExp.rebellion.tension / 100) * 10); // progress scales with tension
+					} else {
+						V.SecExp.rebellion.slave += jsRandom(1, 5);
+					}
+				}
+			} else {
+				if (jsRandom(1, 100) < citizen) {
+					V.SecExp.conflict.rebellionEvents = "citizen";
+					if (V.SecExp.rebellion.tension !== 0) {
+						V.SecExp.rebellion.rabble += Math.trunc(jsRandom(1, 5) * (V.SecExp.rebellion.tension / 100) * 10);
+					} else {
+						V.SecExp.rebellion.rabble += jsRandom(1, 5);
+					}
+				}
+			}
+
+			// if there is an advancement selects a jsRandom mini event
+			const oldTension = V.SecExp.rebellion.tension; let event;
+			if (jsDef(V.SecExp.conflict.rebellionEvents)) {
+				r += `\n\n`;
+					if (V.SecExp.rebellion.tension <= 33) {
+						if (V.SecExp.conflict.rebellionEvents === "slave") {
+							event = 1;
+						} else {
+							event = 4;
+						}
+					} else if (V.SecExp.rebellion.tension <= 66) {
+						if (V.SecExp.conflict.rebellionEvents === "slave") {
+							event = 2;
+						} else {
+							event = 5;
+						}
+					} else {
+						if (V.SecExp.conflict.rebellionEvents === "slave") {
+							event = 3;
+						} else {
+							event = 6;
+						}
+				}
+
+				r += `<<setNonlocalPronouns $seeDicks>>`; let rand;
+				switch (event) {
+				case  1: // low tension slave rebellion events
+					rand = jsRandom(0, 6);
+					if (rand === 0) {
+						r += `This week several slaves were found plotting the death of their master. They were quickly dealt with, but their owner's choice of punishment did little to calm tensions in the arcology.`;
+					} else if (rand === 1) {
+						r += `This week a large group of slaves attempted to escape. Several were recaptured, but others were deemed too dangerous and were shot on sight. The unfortunate circumstances raised the disapproval of many citizens, either because of the waste of good slaves or the brutality with which the operation was carried. With a bit of luck, however, the incident will be soon forgotten.`;
+					} else if (rand === 2) {
+						r += `This week books of unknown origin and dangerous content were found in the possession of several slaves. They were mostly sociopolitical treaties, making it clear that the intent of the ones responsible was to fan the fire of rebellion. The books were quickly collected and archived, hopefully this affair will not have lasting consequences.`;
+					} else if (rand === 3) {
+						r += `This week a citizen was caught giving refuge to an escaped slave. He was not able to pay for the value of the stolen goods, so he was processed as the case required and the slave returned to their rightful master. Many questions however remain without answers.`;
+					} else if (rand === 4) {
+						r += `This week a member of a well known anti-slavery group was caught trying to infiltrate the arcology. During the capture attempt shots were fired and several guards were injured, and in the end the fugitive unfortunately managed to escape. Reports indicate several slaves helped the criminal, some going as far as using themselves as shields against the bullets of the security drones.`;
+					} else if (rand === 5) {
+						r += `This week a slave was caught attempting to sabotage a machine in one of the factories. _HeU explained _hisU action as "trying to defend _himselfU from a dangerous machine". Reports confirmed that the apparatus is indeed quite deadly, having killed several slaves since it was installed, but the expert way _heU handled the sabotage leaves open the possibility of a deliberate plan or even external help.`;
+					} else {
+						r += `This week a slave was found dead in one of the sewer tunnels. It seems _heU was stabbed repeatedly with a sharp object. _HeU was fairly famous for _hisU capabilities as a slave trainer; _hisU old master spent not an insignificant amount of money trying to find _himU once he realized _heU was missing. The episode might have been a simple mugging gone wrong, but _hisU activities as a slave breaker might have played a role in _hisU homicide.`;
+					}
+					V.SecExp.rebellion.tension += jsRandom(1, 5); break;
+				case  2: // med tension slave rebellion events
+					rand = jsRandom(0, 5);
+					if (rand === 0) {
+						r += `This week some strange reports came in: it seems some assemblies of slaves were observed several nights in a row. The slaves were traced and their masters notified, but many suspect there may be something deeper than a few slaves congregating in the night.`;
+					} else if (rand === 1) {
+						r += `This week an underground railroad was discovered. The rebels did not go down without a fight, but in the end if (V.mercenaries >= 1) {your mercenaries} else {your security drones} managed to destroy the old tunnels they were using to ship out slaves out of the arcology.`;
+					} else if (rand === 2) {
+						r += `This week a famous citizen was assaulted and brutally murdered by his slaves. The ones responsible were apprehended and dealt with easily enough, but the mere fact something like this could have happened is concerning. Those slaves had to be aware of their certain doom.`;
+					} else if (rand === 3) {
+						r += `This week a group of slavers entering the arcology was assaulted. Many reported heavy injuries, but fortunately there were no casualties. The attackers were disguised, but the security systems already identified several slaves who were likely part of the group, based on camera feeds.`;
+					} else if (rand === 4) {
+						r += `This week the waterways were found infected by a virulent pathogen. The cause was later found to be a diseased slave that died while in the maintenance tunnels. It's not clear if the slave was there because of orders given to _himU or if _heU was trying to escape.`;
+					} else {
+						r += `This week a sleeper cell of a famous anti slavery organization was discovered in the low levels of the arcology. The group, however, was aware of the coming security forces and retreated before they could be dealt with.`;
+					}
+					V.SecExp.rebellion.tension += jsRandom(5, 10); break;
+				case  3: // high tension slave rebellion events
+					rand = jsRandom(0, 4);
+					if (rand === 0) {
+						r += `This week a group of slaves took control of one of the manufacturing plants and barricaded themselves inside. It took several days of negotiations and skirmishes to finally end this little insurrection. Many of the slaves involved will be executed in the next few days.`;
+					} else if (rand === 1) {
+						r += `This week a number of shops were burned to the ground by rioting slaves and sympathetic citizens. It took considerable effort for the security forces to take control of the situation. Harsh punishment is required and scheduled for the instigators.`;
+					} else if (rand === 2) {
+						r += `This week a mass escape attempt was barely stopped before becoming a catastrophe. Many citizens were trampled by the desperate horde of slaves. It will take some time to restore the streets involved to working order.`;
+					} else if (rand === 3) {
+						r += `This week a number of riots inflamed the arcology. Many slaves took violent actions against citizens and security personnel. The number of victims keeps getting higher as still now the last sparks of revolt are still active.`;
+					}
+					V.SecExp.rebellion.tension += jsRandom(10, 15); break;
+				case  4:
+					rand = jsRandom(0, 6);
+					if (rand === 0) {
+						r += `This week a citizen refused to pay rent, claiming ideological opposition to the arcology's ownership policies. He was quickly dealt with, but his words might not have fallen silent yet.`;
+					} else if (rand === 1) {
+						r += `This week books of unknown origin and dangerous content were found in the possession of several citizens. They were mostly sociopolitical treaties, making it clear that the intent of the ones responsible was to fan the fire of rebellion. Most of them were bought and archived, but a few are still circling amongst the citizens of the arcology.`;
+					} else if (rand === 2) {
+						r += `This week a citizen was caught giving refuge to other citizens, who would be liable to be enslaved because of their debts. The situation was quickly resolved, but the misplaced generosity of that citizen might have inflamed a few souls.`;
+					} else if (rand === 3) {
+						r += `This week a citizen died in one of the factories. His death sparked some outrage, even some talk of protests against the owners of the factory, but things seem to have calmed down for now.`;
+					} else if (rand === 4) {
+						r += `This week a citizen refused to be evicted from his house. After some negotiations the man was forcibly removed from the property by your security forces. Unfortunately the forced entry caused some damage to the building.`;
+					} else if (rand === 5) {
+						r += `This week a citizen refused to be enslaved as his contract established. With an impressive display of his rhetoric capabilities he managed to gather a small crowd agreeing with his position. The impromptu assembly was promptly disrupted by the drones.`;
+					} else {
+						r += `This week a security drone was found disabled and stripped of important electronic components. It seems the act was not dictated by greed, as the most precious parts of the drone were left on the machine, but rather to cover up something that the drone saw.`;
+					}
+					V.SecExp.rebellion.tension += jsRandom(1, 5); break;
+				case  5:
+					rand = jsRandom(0, 5);
+					if (rand === 0) {
+						r += `This week a factory was subject to a strike by a group of citizens protesting against the owner. They were promptly arrested and the factory returned to its rightful proprietor by your security department.`;
+					} else if (rand === 1) {
+						r += `This week a group of citizens organized a protest against the systemic enslavement of the citizens of the arcology. Their little parade gathered a surprisingly large crowd, but it was nonetheless quickly suppressed by your forces.`;
+					} else if (rand === 2) {
+						r += `This week the security department registered the formation of several assemblies of citizens, whose purpose seems to be political in nature. For now no further steps were taken, but it's a worrying sign of further political opposition within the arcology.`;
+					} else if (rand === 3) {
+						r += `This week there was a protest against one of the wealthiest citizen of the arcology. Many criticize his near monopoly. Supporters of the citizen met the protesters on the streets and it was just thanks to the intervention of the security drones that violence was avoided.`;
+					} else if (rand === 4) {
+						r += `This week several cameras were sabotaged and in many cases damaged beyond repair. A group of anonymous citizens claims to be responsible; their motivation is apparently the excessive surveillance in the arcology and their attack a response to the breach of their privacy.`;
+					} else {
+						r += `This week several citizens barricaded themselves in a private brothel. It seems their intention is to protest against the use of ex-citizens in the sex trade, claiming that such a position is unfitting for them. The problem was quickly resolved with the intervention of the security department.`;
+					}
+					V.SecExp.rebellion.tension += jsRandom(5, 10); break;
+				case  6:
+					rand = jsRandom(0, 4);
+					if (rand === 0) {
+						r += `This week the arcology was shaken by a number of strikes throughout the manufacturing levels. Many lament the predatory nature of Free Cities society, many other just want to cause damage to their perceived oppressors. It was a significant effort for the security department to stop all protests.`;
+					} else if (rand === 1) {
+						r += `This week several factories were set aflame by their workers. The security department worked day and night to control the fire and apprehend the criminals behind the act. Many are known dissidents, but there are a fair few new faces within them. This is a worrying sign.`;
+					} else if (rand === 2) {
+						r += `This week numerous riots exploded all over the arcology. Many citizens took to the streets to protest against the arcology owner and its supporters. The security forces slowly managed to stop the rioters, with no small amount of trouble and only through generous use of violence.`;
+					} else if (rand === 3) {
+						r += `This week a massive protest of citizens and slaves gathered just outside the penthouse. The crowd was dispersed only after several hours. There were several victims from both sides and no shortage of injured.`;
+					}
+					V.SecExp.rebellion.tension += jsRandom(10, 15); break;
+				}
+
+				V.SecExp.rebellion.tension = Math.clamp(V.SecExp.rebellion.tension, 0, 100);
+			} else if (V.SecExp.rebellion.tension > 0) {
+				// otherwise tension decays
+				r += `\n\n`;
+				r += `<strong>Tension</strong>:`;
+				if (V.riotUpgrades.freeMedia >= 1) {
+					r += `The guaranteed free media access you offer does wonders to lower tensions in the arcology.`;
+					V.SecExp.rebellion.tension = Math.trunc(Math.clamp(V.SecExp.rebellion.tension - V.riotUpgrades.freeMedia / 2, 0, 100));
+				}
+				r += `In the absence of noteworthy events, tensions in the arcology are able to relax.`;
+				V.SecExp.rebellion.tension = Math.trunc(Math.clamp(V.SecExp.rebellion.tension * 0.97, 0, 100));
+			}
+			r+=`\n`;
+			if (V.SecExp.rebellion.tension < oldTension) {
+				r += `\nThis week <span class='green'>tensions relaxed.</span>`;
+			} else if (V.SecExp.rebellion.tension === oldTension && V.SecExp.rebellion.tension !== 0) {
+				r += `\nThis week <span class='yellow'>tensions did not change.</span>`;
+			} else if (V.SecExp.rebellion.tension > oldTension) {
+				r += `\nThis week <span class='red'>tension rose</span>`;
+				if(jsDef(V.SecExp.conflict.rebellionEvents)) {
+					r += ` and <span class='red'> ${V.SecExp.conflict.rebellionEvents} malcontent increased.</span>`;
+				} else {
+					r += `.`;
+				}
+			} else if (!Number.isInteger(V.SecExp.rebellion.tension)) {
+				r += `\nError: tension is outside accepted range.`;
+			}
+
+			// rolls for rebellions
+			if (V.SecExp.rebellion.slave >= 100) {
+				if (jsRandom(1, 100) <= 80) {	// 80% of firing a rebellion once progress is at 100
+					V.SecExp.conflict.type = 0;
+					V.SecExp.rebellion.slave = 0;
+					V.citizenProgress *= 0.2;
+				} else {
+					V.SecExp.rebellion.slave = 100;
+				}
+			} else if (V.SecExp.rebellion.rabble >= 100) {
+			if (jsRandom(1, 100) <= 80) {
+					V.SecExp.conflict.type = 1;
+					V.SecExp.rebellion.rabble = 0;
+					V.SecExp.rebellion.slave *= 0.2;
+				} else {
+					V.SecExp.rebellion.rabble = 100;
+				}
+			}
+
+			if (V.SecExp.settings.rebellion.force === 1 && jsDef(V.SecExp.conflict.occuredThisWeek) === false) {
+				if (jsRandom(1, 100) <= 50) {
+					V.SecExp.conflict.type = 0;
+				} else {
+					V.SecExp.conflict.type = 1;
+				}
+			}
+
+			// if a rebellion fires determine amount of rebels and rebelling units
+			if (V.SecExp.conflict.type <= 1) {
+				eventObjectCreation(mode);
+				if (V.SecExp.conflict.type === 0) {
+					V.SecExp.conflict.rebelling = [];
+					V.SecExp.conflict.loyal = [];
+
+					for  (let i = 0; i < V.SecExp.army.unitPool.length; i++) { // calc if units rebel
+						if (V.SecExp.army.units[V.SecExp.army.unitPool[i]] !== undefined && V.SecExp.army.units[V.SecExp.army.unitPool[i]] !== "Bots") {
+							for (let x = 0; x < V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads.lenth; x++) {
+								if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].loyalty < 10) {
+									if (jsRandom(1, 100) <= 70) {
+										V.SecExp.conflict.rebelling.push(V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].name);
+									}
+								} else if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].loyalty < 33) {
+									if (jsRandom(1, 100) <= 30) {
+										V.SecExp.conflict.rebelling.push(V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].name);
+									}
+								} else if (V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].loyalty < 66) {
+									if (jsRandom(1, 100) <= 10) {
+										V.SecExp.conflict.rebelling.push(V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].name);
+									}
+								}
+								if (!(V.SecExp.conflict.rebelling.includes(V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].name))) {
+									V.SecExp.conflict.loyal.push(V.SecExp.army.units[V.SecExp.army.unitPool[i]].squads[x].name);
+								}
+							}
+						}
+					}
+				}
+				delete V.SecExp.rebellion.weeksSinceLast;
+				V.SecExp.conflict.attacker.equip = Math.clamp(V.SecExp.edicts.weaponsLaw + jsRandom(-2, 1), 0, 4);
+			} else {
+				if (jsDef(V.SecExp.rebellion.weeksSinceLast)) {
+					V.SecExp.rebellion.weeksSinceLast++;
+				} else {
+					V.SecExp.rebellion.weeksSinceLast = 1;
+				}
+			}
+			return r;
+		}
+	} // Closes Generator check funtion. */
+})(); // Closes check funtion.
+
+/* App.SecExp.UnitUpgradeCosts = function(Unit) {
+	const V = State.variables, T = State.temporary,
+	UpgradeCost = {equip:250, secBots:250}; T.cost = {};
+	T.cost.overall = 0; T.cost.size = 0; T.cost.equip=0; T.cost.commissars = 0;
+	T.cost.cyber = 0; T.cost.medics = 0; T.cost.sf = 0;
+	if (Unit === V.secBots) {
+		if (V.secBots.maxTroops < 80) {
+ T.cost.size += 5000;
+		} else if (V.SF.Toggle && V.SF.Active >= 1 && V.secBots.maxTroops < 100 && V.SFSupportLevel >= 1) {
+			T.cost.size += 5000 + 10 * UpgradeCost.secBots * V.secBots.equip;
+		}
+		if (V.secBots.equip < 3) { T.cost.equip += UpgradeCost.secBots * V.secBots.maxTroops + 1000; }
+	} else {
+		if (Unit[V.targetIndex].maxTroops < 50) {
+						T.cost.size += 5000 + 10 * UpgradeCost.equip * (Unit[V.targetIndex].equip + Unit[V.targetIndex].commissars + Unit[V.targetIndex].cyber + Unit[V.targetIndex].SF);
+		}
+		if (Unit[V.targetIndex].equip < 3) { T.cost.equip += UpgradeCost.equip * Unit[V.targetIndex].maxTroops + 1000; }
+		if (Unit[V.targetIndex].commissars < 2) { T.cost.commissars += UpgradeCost.equip * Unit[V.targetIndex].maxTroops + 1000; }
+		if (Unit[V.targetIndex].cyber < 1 && (V.prostheticsUpgrade >= 2 || V.researchLab.advCombatPLimb === 1) ) { T.cost.cyber += UpgradeCost.equip * Unit[V.targetIndex].maxTroops + 2000; }
+		if (Unit[V.targetIndex].medics < 1) { T.cost.medics += UpgradeCost.equip * Unit[V.targetIndex].maxTroops + 1000; }
+		if (Unit[V.targetIndex].SF < 1 && V.SF.Toggle && V.SF.Active >= 1) { T.cost.sf += UpgradeCost.equip * Unit[V.targetIndex].maxTroops + 5000; }
+	}
+	T.cost.overall += T.cost.size+T.cost.equip+T.cost.commissars+T.cost.cyber+T.cost.medics+T.cost.sf;
+};
+
+
+App.SecExp.report = (function() {
+		return {
+		trade:trade,
+		security:security,
+		authority:authority,
+		rebellionInit:rebellionInit,
+		conflictEnd:conflictEnd,
+		enemyTroops:enemyTroops,
+	};
+
+	function trade() {
+		let tradeChange = 0;
+		const V = State.variables; let r = ``;
+		if (V.week < 30) {
+			r += `The world economy is in good enough shape to sustain economic growth. Trade flows liberally in all the globe.`;
+			tradeChange += 1;
+		} else if (V.week < 60) {
+			r += `The world economy is deteriorating, but still in good enough shape to sustain economic growth.`;
+			tradeChange += 0.5;
+		} else if (V.week < 90) {
+			r += `The world economy is deteriorating, but still in decent enough shape to sustain economic growth.`;
+		} else if (V.week < 120) {
+			r += `The world economy is deteriorating and the slowing down of global growth is starting to have some effect on trade flow.`;
+			tradeChange -= 1;
+		} else {
+			r += `The world economy is heavily deteriorated. The slowing down of global growth has a great negative effect on trade flow.`;
+			tradeChange -= 2;
+		}
+
+		if(V.SecExp.settings.battle.enabled > 0 && jsDef(V.SecExp.battle.count) && jsDef(V.SecExp.battle.weeksSinceLast)) {
+			if (V.SecExp.battle.weeksSinceLast < 2) {
+				r += `The recent attack has a negative effect on the trade of the arcology.`;
+				tradeChange -= 1;
+			} else if (V.SecExp.battle.weeksSinceLast < 4) {
+				r += `While some time has passed, the last attack still has a negative effect on the commercial activity of the arcology.`;
+				tradeChange -= 0.5;
+			}
+		}
+
+		if(V.SecExp.settings.rebellion.enabled > 0 && jsDef(V.SecExp.rebellion.count)) {
+			if (V.SecExp.rebellion.weeksSinceLast < 2) {
+				r += `The recent rebellion has a negative effect on the trade of the arcology.`;
+				tradeChange -= 1;
+			} else if (V.SecExp.rebellion.weeksSinceLast < 4) {
+				r += `While some time has passed, the last rebellion still has a negative effect on the commercial activity of the arcology.`;
+				tradeChange -= 0.5;
+			}
+		}
+
+		if (V.terrain === "urban") {
+			r += `Since your arcology is located in the heart of an urban area, its commerce is naturally vibrant.`;
+			tradeChange++;
+		}
+		if (V.terrain === "ravine") {
+			r += `Since your arcology is located in the heart of a ravine, its commerce is hindered by a lack of accessibility.`;
+			tradeChange -= 0.5;
+		}
+
+		if (V.PC.career === "wealth" || V.PC.career === "capitalist" || V.PC.career === "celebrity" || V.PC.career === "BlackHat") {
+			tradeChange += 1;
+		} else if (V.PC.career === "escort" || V.PC.career === "servant" || V.PC.career === "gang") {
+			tradeChange -= 0.5;
+		}
+
+		if (V.rep > 18000) {
+			r += `Your extremely high reputation attracts trade from all over the world.`;
+		} else if (V.rep > 12000) {
+			r += `Your high reputation attracts trade from all over the world.`;
+		}
+
+		r += `<<setAssistantPronouns>>`;
+		if (V.assistantPower === 1) {
+			r += `Thanks to the computing power available to _himA, V.assistantName is able to guide the commercial development of the arcology to greater levels.`;
+			tradeChange++;
+		} else if (V.assistantPower >= 2) {
+			r += `Thanks to the incredible computing power available to _himA, V.assistantName is able to guide the commercial development of the arcology to greater levels.`;
+			tradeChange += 2;
+		}
+
+		if (jsDef(V.SecExp.edicts.tradeLegalAid)) {
+			r += `Your support in legal matters for new businesses helps improve the economic dynamicity of your arcology, boosting commercial activities.`;
+			tradeChange += 1;
+		}
+
+		if (jsDef(V.SecExp.edicts.taxTrade)) {
+			r += `The fees imposed on transitioning goods do little to earn you the favor of the companies making use of your arcology.`;
+			tradeChange -= 1;
+		}
+
+		if (V.weapManu === 1) {
+			r += `The weapons manufacturing facility of the arcology attracts a significant amount of trade.`;
+			tradeChange += 0.5 * (V.weapProductivity + V.weapLab);
+		}
+		if (V.SecExp.buildings.hub.active > 0) {
+			if (jsDef(V.airport) === false) {
+				r += `The airport, while small, helps facilitate the commercial development of the arcology.`;
+				tradeChange += 1;
+			} else if (V.airport === 2) {
+				r += `The airport, while fairly small, helps facilitate the commercial development of the arcology.`;
+				tradeChange += 1.5;
+			} else if (V.airport === 3) {
+				r += `The airport helps facilitate the commercial development of the arcology.`;
+				tradeChange += 2;
+			} else if (V.airport === 4) {
+				r += `The airport is a great boon to the commercial development of the arcology.`;
+				tradeChange += 2.5;
+			} else {
+				r += `The airport is an incredible boon to the commercial development of the arcology.`;
+				tradeChange += 3;
+			}
+
+			if (V.terrain !== "oceanic" && V.terrain !== "marine") {
+				if (jsDef(V.railway) === false) {
+					r += `The railway network's age and limited extension limit commercial activity.`;
+				} else if (V.railway === 2) {
+					r += `The railway network is a great help to the commercial development of the arcology, but its limited extension hampers its potential.`;
+					tradeChange += 1;
+				} else if (V.railway === 3) {
+					r += `The railway network is a great help to the commercial development of the arcology.`;
+					tradeChange += 1.5;
+				} else {
+					r += `The railway network is a huge help to the commercial development of the arcology. Few in the world can boast such a modern and efficient transport system.`;
+					tradeChange += 2;
+				}
+			} else {
+				if (jsDef(V.docks) === false) {
+					r += `The docks' age and limited size limit commercial activity.`;
+				} else if (V.docks === 2) {
+					r += `The docks are a great help to the commercial development of the arcology, but their limited size hampers its potential.`;
+					tradeChange += 1;
+				} else if (V.docks === 3) {
+					r += `The docks are a great help to the commercial development of the arcology.`;
+					tradeChange += 1.5;
+				} else {
+					r += `The docks are a huge help to the commercial development of the arcology. Few in the world can boast such a modern and efficient transport system.`;
+					tradeChange += 2;
+				}
+			}
+		}
+
+		if (V.SF.Toggle && V.SF.Active >= 1 && V.SF.Size > 10) {
+			r += `Having a powerful special force, increases trade security.`;
+			tradeChange += V.SF.Size/10;
+		}
+
+		if (tradeChange > 0) {
+			r += `This week <span class='green'>trade improved.</span> `;
+		} else if (tradeChange === 0) {
+			r += `This week <span class='yellow'>trade did not change.</span> `;
+		} else {
+			r += `This week <span class='red'>trade diminished.</span> `;
+		}
+
+		let AWeekGrowth = 0;
+		if (V.trade <= 20) {
+			r += `The almost non-existent trade crossing the arcology <span class='yellow'>does little to promote growth.</span> `;
+		} else if (V.trade <= 40) {
+			r += `The low level of trade crossing the arcology promotes a <span class='green'>slow yet steady growth</span> of its economy.`;
+			AWeekGrowth += 1.5;
+		} else if (V.trade <= 60) {
+			r += `With trade at positive levels, the <span class='green'>prosperity of the arcology grows more powerful.</span> `;
+			AWeekGrowth += 2.5;
+		} else if (V.trade <= 80) {
+			r += `With trade at high levels, the <span class='green'>prosperity of the arcology grows quickly and violently.</span> `;
+			AWeekGrowth += 3.5;
+		} else {
+			r += `With trade at extremely high levels, the <span class='green'>prosperity of the arcology grows with unprecedented speed.</span> `;
+			AWeekGrowth += 4.5;
+		}
+
+		V.trade = Math.clamp(V.trade + tradeChange, 0, 100);
+		return r;
+	} // Closes trade report funtion.
+
+	function security() {
+		const V = State.variables; let r = ``;
+		let emigration = 0, immigration = 0;
+		if (V.ACitizens > V.oldACitizens) {
+			immigration += V.ACitizens - V.oldACitizens;
+		} else {
+			emigration += V.oldACitizens - V.ACitizens; // takes into account citizens leaving and those getting enslaved
+		}
+		let secGrowth = 0,
+		secRest = 0,
+		restGrowth = 0,
+		newSec = 0,
+		crimeGrowth = 0,
+		crimeCap = 0,
+		newCrime = 0,
+		recruits = 0,
+		recruitsMultiplier = 1,
+		newMercs = 0;
+
+		if (V.useTabs === 0) {
+			r += `&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \n__Security__`;
+		}
+		r += `\n`;
+
+		r += `<strong>Security</strong>:`;
+		if (V.terrain === "oceanic") {
+			r += `Due to the <span class='green'>massive economic and logistical challenges</span> of attacking an oceanic arcology, your security force(s)`;
+		} else {
+			r += `The <span class='red'>easily manageable economic and logistical challenges</span> of attacking an ${V.terrain} arcology ensure that your security force(s) do not`;
+		}
+		r += ` have the luxury of focusing exclusively on internal matters.\n`;
+		if (V.secMenials > 0) {
+			r += `${num(V.secMenials)} slaves work to improve the security of your arcology,`;
+			if (V.mercenaries >= 1 && V.arcologyUpgrade.drones === 1) {
+				r += `while your mercenaries and security drones tirelessly patrol the streets to keep them safe.`;
+			} else if (V.arcologyUpgrade.drones === 1) {
+				r += `while your security drones tirelessly patrol the arcology to keep it safe.`;
+			} else {
+				r += `while your loyal subordinates try to keep the arcology safe to the best of their abilities.`;
+			}
+		} else {
+			if (V.mercenaries >= 1 && V.arcologyUpgrade.drones === 1) {
+				r += `Your mercenaries and security drones tirelessly patrol the streets to keep them safe.`;
+			} else if (V.arcologyUpgrade.drones === 1) {
+				r += `Your security drones tirelessly patrol the arcology to keep it safe.`;
+			} else {
+				r += `Your loyal subordinates try to keep the arcology safe to the best of their abilities.`;
+			}
+		}
+
+		// security modifiers
+		if (V.PC.career === "mercenary") {
+			r += `Your past life as a mercenary makes it easier to manage the security of the arcology.`;
+			secGrowth += 1;
+		}
+		if (V.SecExp.smilingMan.fate === 0) {
+			r += `The ex-criminal known to the world as The Smiling Man puts their impressive skills to work, dramatically increasing the efficiency of your security measures.`;
+			secGrowth += 2;
+		}
+		if (V.ACitizens + V.ASlaves <= 5000) {
+			r += `The small number of residents makes their job easier.`;
+			secGrowth += 2;
+		} else if (V.ACitizens + V.ASlaves <= 7500) {
+			r += `The fairly low number of residents makes their job a little easier.`;
+			secGrowth += 1;
+		} else if (V.ACitizens + V.ASlaves <= 10000) {
+			r += `The fairly high number of residents makes their job a little harder.`;
+			secGrowth -= -0.5;
+		} else if (V.ACitizens + V.ASlaves <= 15000) {
+			r += `The high number of residents makes their job harder.`;
+			secGrowth -= 1;
+		} else {
+			r += `The extremely high number of residents makes their job a lot harder.`;
+			secGrowth -= 2;
+		}
+		if (immigration >= 0 && emigration === 0) {
+			if (immigration < 50) {
+				r += `The limited number of immigrants that reached the arcology this week does not have any serious impact on the efficiency of current security measures.`;
+				secGrowth += 0.5;
+			} else if (immigration < 150) {
+				r += `The number of immigrants that reached the arcology this week is high enough to complicate security protocols.`;
+				secGrowth -= 0.2;
+			} else if (immigration < 300) {
+				r += `The high number of immigrants that reached the arcology this week complicates security protocols.`;
+				secGrowth -= 0.5;
+			} else if (immigration < 500) {
+				r +=`The high number of immigrants that reached the arcology this week severely complicates security protocols.`;
+				secGrowth -= 1;
+			} else {
+				r += `The extremely high number of immigrants that reached the arcology this week severely complicates security protocols.`;
+				secGrowth -= 2;
+			}
+		}
+		if (V.visitors < 300) {
+			r += `The limited number of visitors coming and going did not have any serious impact on the efficiency of current security measures.`;
+			secGrowth += 0.5;
+		} else if (immigration < 750) {
+			r += `The number of visitors coming and going somewhat complicates security protocols.`;
+			secGrowth -= 0.2;
+		} else if (immigration < 1500) {
+			r += `The high number of visitors coming and going complicates security protocols.`;
+			secGrowth -= 0.5;
+		} else if (immigration < 2500) {
+			r += `The high number of visitors coming and going greatly complicates security protocols.`;
+			secGrowth -= 1;
+		} else {
+			r += `The extremely high number of visitors coming and going severely complicates security protocols.`;
+			secGrowth -= 2;
+		}
+		if (emigration !== 0 && immigration === 0) {
+			if (emigration < 100) {
+				r += `The limited reduction in citizens this week does not have any serious impact on the efficiency of current security measures.`;
+				secGrowth += 0.5;
+			} else if (emigration < 300) {
+				r += `The reduction in citizens this week is high enough to complicate security protocols.`;
+				secGrowth -= 0.2;
+			} else if (emigration < 600) {
+				r += `The large reduction in citizens this week complicates security protocols.`;
+				secGrowth -= 0.5;
+			} else if (emigration < 1000) {
+				r += `The huge reduction in citizens this week severely complicates security protocols.`;
+				secGrowth -= 1;
+			} else {
+				r += `The extreme reduction in citizens this week severely complicates security protocols.`;
+				secGrowth -= 2;
+			}
+		}
+		if (V.SecExp.core.crimeLow < 20) {
+			r += `Crime is a distant problem in the arcology, which makes improving security easier.`;
+			secGrowth += 1;
+		} else if (V.SecExp.core.crimeLow < 40) {
+			r += `Crime is a minor problem in the arcology, not serious enough to disrupt security efforts.`;
+		} else if (V.SecExp.core.crimeLow < 60) {
+			r += `Crime is an issue in the arcology, which makes improving security harder.`;
+			secGrowth -= 0.5;
+		} else if (V.SecExp.core.crimeLow < 80) {
+			r += `Crime is an overbearing problem in the arcology, which makes improving security a lot harder.`;
+			secGrowth -= 1;
+		} else {
+			r += `Crime is sovereign in the arcology, which makes improving security extremely difficult.`;
+			secGrowth -= 2;
+		}
+		if (V.SecExp.core.authority < 5000) {
+			r += `The low authority you hold on the arcology hampers the efforts of your security department.`;
+			secGrowth -= 1;
+		} else if (V.SecExp.core.authority < 7500) {
+			r += `The limited authority you hold on the arcology hampers the efforts of your security department.`;
+			secGrowth -= 0.5;
+		} else if (V.SecExp.core.authority < 10000) {
+			r += `The authority you hold on the arcology does not significantly impact the efforts of your security department.`;
+		} else if (V.SecExp.core.authority < 15000) {
+			r += `The high authority you hold on the arcology facilitates the security department's work.`;
+			secGrowth += 0.5;
+		} else {
+			r += `The absolute authority you hold on the arcology makes the security department's work a lot easier.`;
+			secGrowth += 1;
+		}
+		if (V.activeUnits >= 6) {
+			r += `Your military is the size of a small army. Security is easier to maintain with such forces at your disposal.`;
+			secGrowth += 0.5;
+		}
+		if(jsDef(V.SecExp.battle.count) && jsDef(V.SecExp.battle.weeksSinceLast)) {
+			if (V.SecExp.battle.weeksSinceLast < 3) {
+				r += `The recent attack has a negative effect on the security of the arcology.`;
+				secGrowth -= 1;
+			} else if (V.SecExp.battle.weeksSinceLast < 5) {
+				r += `While some time has passed, the last attack still has a negative effect on the security of the arcology.`;
+				secGrowth -= 0.5;
+			} else {
+				r += `The arcology has not been attacked in a while, which has a positive effect on security.`;
+				secGrowth += 0.5;
+			}
+		}
+
+		if (V.SecExp.buildings.hub.active > 0) {
+			if (V.terrain !== "oceanic" && V.terrain !== "marine") {
+				secGrowth -= (V.airport + V.railway - V.hubSecurity * 3) / 2;
+			} else {
+				secGrowth -= (V.airport + V.docks - V.hubSecurity * 3) / 2;
+			}
+			r += `The transport hub, for all its usefulness, is a hotspot of malicious `;
+			if (V.airport + V.docks > V.hubSecurity * 3) {
+				r += `activity and hub security forces are not sufficient to keep up with all threats.`;
+			} else {
+				r += `activity, but the hub security forces are up to the task.`;
+			}
+		}
+
+		if (jsDef(V.blackOps)) {
+			r += `Your black ops team proves to be a formidable tool against anyone threatening the security of your arcology.`;
+			secGrowth += 0.5 * jsRandom(1, 2);
+		}
+
+		if (V.SecExp.settings.rebellion.enabled > 0) {
+			if (V.SecExp.rebellion.garrison.assistantTime > 0) {
+				r += `With the central CPU core of the assistant down, managing security is a much harder task. Inevitably some little but important details will slip past your agents.`;
+				r += `It will still take `;
+				if (V.SecExp.rebellion.garrison.assistantTime> 1) {
+					r += `${V.SecExp.rebellion.garrison.assistantTime} weeks`;
+					} else {
+						r+= `a week`;
+					}
+					r += ` to finish repair works.`;
+				secGrowth--;
+				crimeGrowth++;
+				V.SecExp.rebellion.garrison.assistantTime--; IncreasePCSkills('engineering', 0.1);
+			} else {
+				delete V.SecExp.rebellion.garrison.assistantTime;
+			}
+		}
+
+		if (V.SF.Toggle && V.SF.Active >= 1) {
+			if (V.SFSupportLevel >= 3) {
+				r += `The two squads of V.SF.Lower assigned to the Security HQ provide an essential help to the security department.`;
+			}
+			if (V.SFSupportLevel >= 2) {
+				r += `The training officers of V.SF.Lower assigned to the Security HQ improve its effectiveness.`;
+			}
+			if (V.SFSupportLevel >= 1) {
+				r += `Providing your Security Department with equipment from V.SF.Lower slightly boosts the security of your arcology.`;
+			}
+		}
+
+		// resting point
+		secRest  =  V.SecExp.security.low * (Math.clamp(V.secMenials, 0, V.reqMenials) / V.reqMenials);
+		if (secRest < 0) {
+			secRest = 20;
+		}
+		if (secRest < V.SecExp.security.low && V.SecExp.security.hq.active === 1) {
+			r += `The limited staff assigned to the HQ hampered the improvements to security achieved this week.`;
+		} else if (secRest < V.SecExp.security.low) {
+			r += `The limited infrastructure available slowly erodes away the security level of the arcology.`;
+		}
+
+		r += `The security level of the arcology is `;
+		if (V.SecExp.security.cap > (secRest + 5)) {
+			r += `over its effective resting point, limiting the achievable growth this week.`;
+			secGrowth *= 0.5;
+		} else if (V.SecExp.security.cap < (secRest - 5)) {
+			r += `under its effective resting point, speeding up its growth.`;
+			secGrowth *= 1.5;
+		} else if (V.SecExp.security.cap === secRest) {
+			r += `at its effective resting point, this severely limits the influence of external factors on the change achievable this week.`;
+			secGrowth *= 0.3;
+		} else {
+			r += `near its effective resting point, this severely limits the influence of external factors on the change achievable this week.`;
+			if (secGrowth < 0) {
+				secGrowth *= 0.3;
+			}
+		}
+		restGrowth = (secRest - V.SecExp.security.cap) * 0.2;
+		newSec = Math.trunc(V.SecExp.security.cap + secGrowth + restGrowth);
+		if (newSec < V.SecExp.security.cap) {
+			r += `This week <span class='red'>security decreased.</span> `;
+		} else if (newSec === V.SecExp.security.cap) {
+			r += `This week <span class='yellow'>security did not change.</span> `;
+		} else {
+			r += `This week <span class='green'>security improved.</span> `;
+		}
+		V.SecExp.security.cap = Math.clamp(newSec, 0, 100);
+
+		r += `\n\n <strong>Crime</strong>:`;
+		// crime modifiers
+		r += `Due to the deterioration of the old world countries, organized crime focuses more and more on the prosperous Free Cities, yours included. This has a `;
+		if (V.week < 30) {
+			r += `small`;
+			crimeGrowth += 0.5;
+		} else if (V.week < 60) {
+			r += `noticeable`;
+			crimeGrowth += 1;
+		} else if (V.week < 90) {
+			r += `moderate`;
+			crimeGrowth += 1.5;
+		} else if (V.week < 120) {
+			r += `big`;
+			crimeGrowth += 2;
+		} else {
+			r += `huge`;
+			crimeGrowth += 2.5;
+		}
+		r += `impact on the growth of criminal activities in your arcology.`;
+
+		if (V.arcologies[0].prosperity < 50) {
+			r += `The low prosperity of the arcology facilitates criminal recruitment and organization.`;
+			crimeGrowth += 1;
+		} else if (V.arcologies[0].prosperity < 80) {
+			r += `The fairly low prosperity of the arcology facilitates criminal recruitment and organization.`;
+			crimeGrowth += 0.5;
+		} else if (V.arcologies[0].prosperity < 120) {
+			r += `The prosperity of the arcology is not high or low enough to have significant effects on criminal recruitment and organization.`;
+		} else if (V.arcologies[0].prosperity < 160) {
+			r += `The prosperity of the arcology is high enough to provide its citizens a decent life, hampering criminal recruitment and organization.`;
+			crimeGrowth -= 0.5;
+		} else if (V.arcologies[0].prosperity < 180) {
+			r += `The prosperity of the arcology is high enough to provide its citizens a decent life, significantly hampering criminal recruitment and organization.`;
+			crimeGrowth -= 1;
+		} else {
+			r += `The prosperity of the arcology is high enough to provide its citizens a very good life, significantly hampering criminal recruitment and organization.`;
+			crimeGrowth -= 2;
+		}
+		if (V.ASlaves < 1000) {
+			r += `The low number of slaves in the arcology does not hinder the activity of law enforcement, limiting crime growth.`;
+			crimeGrowth -= 1;
+		} else if (V.ASlaves < 2000) {
+			r += `The fairly low number of slaves in the arcology does not hinder significantly the activity of law enforcement, limiting crime growth.`;
+			crimeGrowth -= 0.5;
+		} else if (V.ASlaves < 3000) {
+			r += `The number of slaves in the arcology is becoming an impediment for law enforcement, facilitating crime growth.`;
+			crimeGrowth += 1;
+		} else {
+			r += `The number of slaves in the arcology is becoming a big issue for law enforcement, facilitating crime growth.`;
+			crimeGrowth += 1.5;
+		}
+		if (V.SecExp.security.cap <= 20) {
+			r += `The security measures in place are severely limited, allowing crime to grow uncontested.`;
+		} else if (V.SecExp.security.cap <= 50) {
+			r += `The security measures in place are of limited effect and use, giving only mixed results in their fight against crime.`;
+			crimeGrowth -= 1.5;
+		} else if (V.SecExp.security.cap <= 75) {
+			r += `The security measures in place are well developed and effective, making a serious dent in the profitability of criminal activity in your arcology.`;
+			crimeGrowth -= 3;
+		} else {
+			r += `The security measures in place are extremely well developed and very effective, posing a serious threat even to the most powerful criminal organizations in existence.`;
+			crimeGrowth -= 5.5;
+		}
+		if (V.SecExp.core.authority < 5000) {
+			r += `Your low authority allows crime to grow undisturbed.`;
+			crimeGrowth += 1;
+		} else if (V.SecExp.core.authority < 7500) {
+			r += `Your relatively low authority facilitates criminal activities.`;
+			crimeGrowth += 0.5;
+		} else if (V.SecExp.core.authority < 10000) {
+			r += `Your authority is not high enough to discourage criminal activity.`;
+		} else if (V.SecExp.core.authority < 15000) {
+			r += `Your high authority is an effective tool against crime.`;
+			crimeGrowth -= 1;
+		} else {
+			r += `Your absolute authority is an extremely effective tool against crime.`;
+			crimeGrowth -= 2;
+		}
+		if (V.cash >= 100000) {
+			r += `Your great wealth acts as a beacon for the greediest criminals, calling them to your arcology as moths to a flame.`;
+			crimeGrowth += 0.5;
+		}
+		if (jsDef(V.marketInfiltration)) {
+			crimeGrowth += 0.5 * jsRandom(1, 2);
+		}
+
+		// crime cap
+		crimeCap = Math.trunc(Math.clamp(V.SecExp.core.crimeCap + (V.SecExp.core.crimeCap - V.SecExp.core.crimeCap * (V.secMenials / V.reqMenials)), 0, 100));
+		if (crimeCap > V.SecExp.core.crimeCap && V.SecExp.security.hq.active === 1) {
+			r += `The limited staff assigned to the HQ allows more space for criminals to act.`;
+		}
+		newCrime = Math.trunc(Math.clamp(V.SecExp.core.crimeLow + crimeGrowth, 0, crimeCap));
+		if (newCrime > V.SecExp.core.crimeLow) {
+			r += `This week <span class='red'>crime increased.</span> `;
+		} else if (newCrime === V.SecExp.core.crimeLow) {
+			r += `This week <span class='yellow'>crime did not change.</span> `;
+		} else {
+			r += `This week <span class='green'>crime decreased.</span> `;
+		}
+		V.SecExp.core.crimeLow = Math.clamp(newCrime, 0, 100);
+
+		if (V.SecExp.edicts.militiaLevel >= 0 || V.activeUnits >= 1) {
+			r += `\n\n <strong> Military</strong>:`; // militia
+			if (V.SF.Toggle && V.SF.Active >= 1 && V.SF.Size > 10) {
+				r += `Having a powerful special force attracts a lot of citizens, hopeful that they may be able to fight along side it.`;
+			recruitsMultiplier *= 1 + (jsRandom(1, (Math.round(V.SF.Size / 10))) / 20); // not sure how high V.SF.Size goes, so I hope this makes sense
+			}
+			if (V.propCampaign >= 1 && V.propFocus === "recruitment") {
+				if (V.RecuriterOffice === 0 || V.Recruiter === 0) {
+					if (jsDef(V.SecExp.edicts.propCampaignBoost)) {
+						recruitsMultiplier *= 1.1;
+					} else {
+						recruitsMultiplier *= 1.05;
+					}
+				} else {
+					r += `<<setLocalPronouns $Recruiter>>`;
+					r += `''__<span class='pink'>${SlaveFullName(V.Recruiter)}</span> __'' is able to further boost your militia recruitment campaign from ${V.his} PR hub office.`;
+					if (jsDef(V.SecExp.edicts.propCampaignBoost)) {
+						recruitsMultiplier *= 1.2+Math.floor((V.Recruiter.intelligence+V.Recruiter.intelligenceImplant)/650);
+					} else {
+						recruitsMultiplier *= 1.15+Math.floor((V.Recruiter.intelligence+V.Recruiter.intelligenceImplant)/650);
+					}
+				}
+			}
+			if (V.SecExp.edicts.militiaLevel >= 0) {
+				let recruitLimit;
+				if (V.SecExp.edicts.militiaLevel === 1) {
+					r += `Your militia accepts only volunteering citizens, ready to defend their arcology.`;
+					recruitLimit = 0.02;
+					if (V.rep >= 10000) {
+						r += `Many citizens volunteer just to fight for someone of your renown.`;
+						recruitLimit += 0.0025;
+					}
+					if (V.SecExp.core.authority >= 10000) {
+						r += `Many citizens feel it is their duty to fight for you, boosting volunteer enrollment.`;
+						recruitLimit += 0.0025;
+					}
+				} else if (V.SecExp.edicts.militiaLevel === 2) {
+					r += `Adult citizens are required to join the militia for a period of time.`;
+					recruitLimit = 0.05;
+				} else if (V.SecExp.edicts.militiaLevel === 3) {
+					r += `Adult citizens are required to register and serve in the militia whenever necessary.`;
+					recruitLimit = 0.1;
+				} else if (V.SecExp.edicts.militiaLevel === 4) {
+					r += `Every citizen is required to train and participate in the military activities of the arcology.`;
+					recruitLimit = 0.2;
+				}
+
+				if (jsDef(V.SecExp.edicts.lowerRquirements)) {
+					r += `Your lax physical requirements to enter the militia allows for a greater number of citizens to join.`;
+					if (V.SecExp.edicts.militiaLevel === 1) {
+						recruitLimit += 0.0025;
+					} else if (V.SecExp.edicts.militiaLevel === 2) {
+						recruitLimit += 0.005;
+					} else if (V.SecExp.edicts.militiaLevel === 3) {
+						recruitLimit += 0.01;
+					} else if (V.SecExp.edicts.militiaLevel === 4) {
+						recruitLimit += 0.02;
+					}
+				}
+
+
+				if (jsDef(V.SecExp.edicts.noSubhumansInArmy)) {
+						r += `Guaranteeing the purity of your armed forces comes with a small loss of potential recruits.`;
+					if (V.SecExp.edicts.militiaLevel === 2) {
+						recruitLimit -= 0.005;
+					} else if (V.SecExp.edicts.militiaLevel === 3) {
+						recruitLimit -= 0.01;
+					} else if (V.SecExp.edicts.militiaLevel === 4) {
+						recruitLimit -= 0.02;
+					}
+				}
+				if (jsDef(V.SecExp.edicts.pregExemption)) {
+						r += `Many pregnant citizens prefer to avoid military service not to endanger themselves and their children.`;
+					if (V.SecExp.edicts.militiaLevel === 2) {
+						recruitLimit -= 0.005;
+					} else if (V.SecExp.edicts.militiaLevel === 3) {
+						recruitLimit -= 0.01;
+					} else if (V.SecExp.edicts.militiaLevel === 4) {
+						recruitLimit -= 0.02;
+					}
+				}
+
+				if (jsDef(V.SecExp.edicts.militaryExemption)) {
+					r += `Some citizens prefer to contribute to the arcology's defense through financial support rather than military service, making you <span class='yellowgreen'>a small sum.</span> `;
+					if (V.SecExp.edicts.militiaLevel === 2) {
+						recruitLimit -= 0.005;
+					} else if (V.SecExp.edicts.militiaLevel === 3) {
+						recruitLimit -= 0.01;
+					} else if (V.SecExp.edicts.militiaLevel === 4) {
+						recruitLimit -= 0.02;
+					}
+					cashX(250*(1+recruitLimit), "securityExpansion");
+				}
+				recruits = Math.trunc((recruitLimit * V.ACitizens - (V.militiaTotalManpower - V.militiaTotalCasualties)) / 20 * recruitsMultiplier);
+				if (recruits > 0) {
+					V.militiaTotalManpower += recruits;
+					V.militiaFreeManpower += recruits;
+					r += `This week ${recruits} citizens joined the militia.`;
+				} else if (V.SecExp.edicts.militiaLevel === 4) {
+					r += `No citizens joined your militia this week because your society is as militarized as it can get.`;
+				} else if (V.SecExp.edicts.militiaLevel === 1) {
+					r += `There are no more citizens willing to join the arcology armed forces. You'll need to enact higher recruitment edicts if you need more manpower.`;
+				} else {
+					r += `No more citizens could be drafted into your militia. You'll need to enact higher recruitment edicts if you need more manpower.`;
+				}
+				r += `\n`;
+				return r;
+			}
+
+			// mercs
+			if (V.mercenaries >= 1) {
+				newMercs = jsRandom(0, 3);
+				if (V.rep < 6000) {
+					r += `Your low reputation turns some mercenaries away, hoping to find contracts that would bring them more renown.`;
+					newMercs -= 1;
+				} else if (V.rep < 12000) {
+					r += `Your reputation is not high enough to attract many mercenaries to your free city.`;
+				} else {
+					r += `Your reputation attracts many guns for hire who would be proud to have such distinct character on their resume.`;
+					newMercs += 1;
+				}
+				if (V.arcologies[0].prosperity < 50) {
+					r += `The low prosperity of the arcology discourages new guns for hire from coming to your arcology.`;
+					newMercs -= 1;
+				} else if (V.arcologies[0].prosperity < 80) {
+					r += `The fairly low prosperity of the arcology discourages new guns for hire from coming to your arcology.`;
+					newMercs += 1;
+				} else if (V.arcologies[0].prosperity < 120) {
+					r += `The prosperity of the arcology attracts a few mercenaries, hopeful to find lucrative contracts within its walls.`;
+					newMercs += jsRandom(1, 2);
+				} else if (V.arcologies[0].prosperity < 160) {
+					r += `The fairly high prosperity of the arcology attracts some mercenaries, hopeful to find lucrative contracts within its walls.`;
+					newMercs += jsRandom(2, 3);
+				} else if (V.arcologies[0].prosperity < 180) {
+					r += `The high prosperity of the arcology is attracts some mercenaries, hopeful to find lucrative contracts within its walls.`;
+					newMercs += jsRandom(2, 4);
+				} else {
+					r += `The very high prosperity of the arcology attracts a lot of mercenaries, hopeful to find lucrative contracts within its walls.`;
+					newMercs += jsRandom(3, 5);
+				}
+				if (V.SecExp.security.crime.low > 60) {
+					r += `The powerful crime organizations that nested themselves in the arcology have an unending need for cheap guns for hire, many mercenaries flock to your free city in search of employment.`;
+					newMercs += jsRandom(1, 2);
+				}
+				if (V.SF.Toggle && V.SF.Active >= 1 && V.SF.Size > 10) {
+					r += `Having a powerful special force attracts a lot of mercenaries, hopeful that they may be able to fight along side it.`;
+					newMercs += jsRandom(1, Math.round(V.SF.Size/10));
+				}
+				if (jsDef(V.SecExp.edicts.discountMercenaries) > 0) {
+					r += `More mercenaries are attracted to your arcology as a result of the reduced rent.`;
+					newMercs += jsRandom(2, 4);
+				}
+				newMercs = Math.trunc(newMercs / 2);
+				if (newMercs > 0) {
+					V.mercTotalManpower += newMercs;
+					V.mercFreeManpower += newMercs;
+					r += `This week ${newMercs} mercenaries reached the arcology.`;
+				} else {
+					r += `This week no new mercenaries reached the arcology.`;
+				}
+				if (V.mercFreeManpower > 2000) {
+					V.mercTotalManpower -= V.mercFreeManpower - 2000;
+					V.mercFreeManpower = 2000;
+				}
+				r += `\n`;
+			}
+
+			if (V.activeUnits > 0) {
+				// loyalty and training
+				const sL = V.slaveUnits.length;
+				for (let i = 0; i < sL; i++) {
+					let loyaltyChange = 0;
+					r += `\n\n V.slaveUnits[i].platoonName:`;
+					if (V.SecExp.buildings.barracks.upgrades.loyaltyMod >= 1) {
+						loyaltyChange += 2 * V.SecExp.buildings.barracks.upgrades.loyaltyMod;
+						r += `is periodically sent to the indoctrination facility in the barracks for thought correction therapy.`;
+					}
+					if (V.slaveUnits[i].commissars >= 1) {
+						r += `The commissars attached to the unit carefully monitor the officers and grunts for signs of insubordination.`;
+						loyaltyChange += 2 * V.slaveUnits[i].commissars;
+					}
+					if (V.SecExp.edicts.soldierWages === 2) {
+						r += `The slaves greatly appreciate the generous wage given to them for their service as soldiers. Occasions to earn money for a slave are scarce after all.`;
+						loyaltyChange += jsRandom(5, 10);
+					} else if (V.SecExp.edicts.soldierWages === 1) {
+						r += `The slaves appreciate the wage given to them for their service as soldiers, despite it being just adequate. Occasions to earn money for a slave are scarce after all.`;
+						loyaltyChange += jsRandom(-5, 5);
+					} else {
+						r += `The slaves do not appreciate the low wage given to them for their service as soldiers, but occasions to earn money for a slave are scarce, so they're not too affected by it.`;
+						loyaltyChange -= jsRandom(5, 10);
+					}
+					if (jsDef(V.SecExp.edicts.slaveSoldierPrivilege)) {
+						r += `Allowing them to hold material possessions earns you their devotion and loyalty.`;
+						loyaltyChange += jsRandom(1, 2);
+					}
+					if (loyaltyChange > 0) {
+						r += `The loyalty of this unit <span class='green'>increased</span> this week.`;
+					} else if (loyaltyChange === 0) {
+						r += `The loyalty of this unit <span class='yellow'>did not change</span> this week.`;
+					} else {
+						r += `The loyalty of this unit <span class='red'>decreased</span> this week.`;
+					}
+					V.slaveUnits[i].loyalty = Math.clamp(V.slaveUnits[i].loyalty + loyaltyChange, 0, 100);
+					if (V.slaveUnits[i].training < 100 && V.SecExp.buildings.barracks.upgrades.training >= 1) {
+						r += `\nThe unit is able to make use of the training facilities to better prepare its soldiers, slowly increasing their experience level.`;
+						V.slaveUnits[i].training += jsRandom(2, 4) * 1.5 * V.SecExp.buildings.barracks.upgrades.training;
+					}
+				}
+				const mL = V.militiaUnits.length;
+				for (let i = 0; i < mL; i++) {
+					r += `\n\nV.militiaUnits[i].platoonName:`;
+					let loyaltyChange = 0;
+					if (V.SecExp.buildings.barracks.upgrades.loyaltyMod >= 1) {
+						loyaltyChange += 2 * V.SecExp.buildings.barracks.upgrades.loyaltyMod;
+						r += `is periodically sent to the indoctrination facility in the barracks for thought correction therapy.`;
+					}
+					if (V.militiaUnits[i].commissars >= 1) {
+						r += `The commissars attached to the unit carefully monitor the officers and grunts for signs of insubordination.`;
+						loyaltyChange += 2 * V.militiaUnits[i].commissars;
+					}
+					if (V.SecExp.edicts.soldierWages === 2) {
+						r += `The soldiers greatly appreciate the generous wage given to them for their service. They are proud to defend their homes while making a small fortune out of it.`;
+						loyaltyChange += jsRandom(5, 10);
+					} else if (V.SecExp.edicts.soldierWages === 1) {
+						r += `The soldiers appreciate the wage given to them for their service, despite it being just adequate. They are proud to defend their homes, though at the cost of possible financial gains.`;
+						loyaltyChange += jsRandom(-5, 5);
+					} else {
+						r += `The soldiers do not appreciate the low wage given to them for their service. Their sense of duty keeps them proud of their role as defenders of the arcology, but many do feel its financial weight.`;
+						loyaltyChange -= jsRandom(5, 10);
+					}
+					if (jsDef(V.SecExp.edicts.militiaSoldierPrivilege)) {
+						r += `Allowing them to avoid rent payment for their military service earns you their happiness and loyalty.`;
+						loyaltyChange += jsRandom(1, 2);
+					}
+					if (loyaltyChange > 0) {
+						r += `The loyalty of this unit <span class='green'>increased</span> this week.`;
+					} else if (loyaltyChange === 0) {
+						r += `The loyalty of this unit <span class='yellow'>did not change</span> this week.`;
+					} else {
+						r += `The loyalty of this unit <span class='red'>decreased</span> this week.`;
+					}
+					V.militiaUnits[i].loyalty = Math.clamp(V.militiaUnits[i].loyalty + loyaltyChange, 0, 100);
+					if (V.militiaUnits[i].training < 100 && V.SecExp.buildings.barracks.upgrades.training >= 1) {
+						r += `\nThe unit is able to make use of the training facilities to better prepare its soldiers, slowly increasing their experience level.`;
+						V.militiaUnits[i].training += jsRandom(2, 4) * 1.5 * V.SecExp.buildings.barracks.upgrades.training;
+					}
+				}
+				const meL = V.mercUnits.length; let loyaltyTotal = 0;
+				for (let i = 0; i < meL; i++) {
+					r += `\n\nV.mercUnits[i].platoonName:`;
+					let loyaltyChange = 0;
+					if (V.SecExp.buildings.barracks.upgrades.loyaltyMod >= 1) {
+						loyaltyChange += 2 * V.SecExp.buildings.barracks.upgrades.loyaltyMod;
+						r += `is periodically sent to the indoctrination facility in the barracks for thought correction therapy.`;
+					}
+					if (V.mercUnits[i].commissars >= 1) {
+						r += `The commissars attached to the unit carefully monitor the officers and grunts for signs of insubordination.`;
+						loyaltyChange += 2 * V.mercUnits[i].commissars;
+					}
+					if (V.SecExp.edicts.soldierWages === 2) {
+						r += `The mercenaries greatly appreciate the generous wage given to them for their service. After all coin is the fastest way to reach their hearts.`;
+						loyaltyChange += jsRandom(5, 10);
+					} else if (V.SecExp.edicts.soldierWages === 1) {
+						r += `The mercenaries do not appreciate the barely adequate wage given to them for their service. Still their professionalism keeps them determined to finish their contract.`;
+						loyaltyChange += jsRandom(-5, 5);
+					} else {
+						r += `The mercenaries do not appreciate the low wage given to them for their service.Their skill would be better served by a better contract and this world does not lack demand for guns for hire.`;
+						loyaltyChange -= jsRandom(5, 10);
+					}
+					if (jsDef(V.SecExp.edicts.mercSoldierPrivilege)) {
+						r += `Allowing them to keep part of the loot gained from your enemies earns you their trust and loyalty.`;
+						loyaltyChange += jsRandom(1, 2);
+					}
+					if (loyaltyChange > 0) {
+						r += `The loyalty of this unit <span class='green'>increased</span> this week.`;
+					} else if (loyaltyChange === 0) {
+						r += `The loyalty of this unit <span class='yellow'>did not change</span> this week.`;
+					} else {
+						r += `The loyalty of this unit <span class='red'>decreased</span> this week.`;
+					}
+					V.mercUnits[i].loyalty = Math.clamp(V.mercUnits[i].loyalty + loyaltyChange, 0, 100);
+					loyaltyTotal += V.mercUnits[i].loyalty;
+					if (V.mercUnits[i].training < 100 && V.SecExp.buildings.barracks.upgrades.training >= 1) {
+						r += `\nThe unit is able to make use of the training facilities to better prepare its soldiers, slowly increasing their experience level.`;
+						V.mercUnits[i].training += jsRandom(2, 4) * 1.5 * V.SecExp.buildings.barracks.upgrades.training;
+					}
+				}
+				if (meL > 0) {
+					V.mercLoyalty = (loyaltyTotal/meL);
+				}
+			}
+		}
+
+		if (jsDef(V.SecExp.buildings.riotControl.upgrades.socity.brainImplant.lv) && V.SecExp.buildings.riotControl.upgrades.socity.brainImplant.resources < 106) {
+			r += `\n\n`;
+			V.SecExp.buildings.riotControl.upgrades.socity.brainImplant.resources += V.brainImplantProject;
+			if (100 - V.SecExp.buildings.riotControl.upgrades.socity.brainImplant.resources <= 0) {
+				r += `The project has been completed!`;
+				V.SecExp.buildings.riotControl.upgrades.socity.brainImplant.resources = 106;
+				V.riotUpkeep -= 5000 * V.SecExp.buildings.riotControl.upgrades.socity.brainImplant.lv;
+				delete V.SecExp.buildings.riotControl.upgrades.socity.brainImplant.lv;
+			} else {
+				r += `The great brain implant project is proceeding steadily. This week we made`;
+				if (V.SecExp.buildings.riotControl.upgrades.socity.brainImplant.lv <= 2) {
+					r += `some small`;
+				} else if (V.SecExp.buildings.riotControl.upgrades.socity.brainImplant.lv <= 4) {
+					r += `some`;
+				} else {
+					r += `good`;
+				}
+				r += `progress.`;
+			}
+		}
+
+		if (V.currentUpgrade.time > 0) {
+			r += `\n\nIn the research lab, ${V.currentUpgrade.name} `;
+			switch (V.currentUpgrade.name) {
+			case "adaptive armored frames":
+			case "advanced synthetic alloys":
+			case "ceramo-metallic alloys":
+			case "rapid action stimulants":
+			case "universal cyber enhancements":
+			case "remote neural links":
+			case "combined training regimens with the special force":
+				r += `are`; break;
+			default:
+				r += `is`;
+			}
+			r += ` being developed, with the objective to enhance `;
+			if (V.currentUpgrade.type === "attack") {
+				r += `attack power`;
+			} else if (V.currentUpgrade.type === "defense") {
+				r += `defense capabilities`;
+			} else if (V.currentUpgrade.type === "hp") {
+				r += `survivability`;
+			} else if (V.currentUpgrade.type === "morale") {
+				r += `standing power`;
+			} else if (V.currentUpgrade.type === "attackAndDefense") {
+				r += `offensive and defensive effectiveness`;
+			} else if (V.currentUpgrade.type === "hpAndMorale") {
+				r += `morale and survivability`;
+			} else if (V.currentUpgrade.type === "all") {
+				r += `offensive,defensive effectiveness in addition to morale and survivability`;
+			}
+			r += `for`;
+			if (V.currentUpgrade.unit === 0) {
+				r += `the security drones`;
+			} else {
+				r += `our human troops`;
+				}
+
+			V.currentUpgrade.time--;
+			if (V.currentUpgrade.time <= 0) {
+				r += `.\n Reports indicate it is ready for deployment and will be issued to `;
+				if (V.currentUpgrade.unit === 0) {
+					r += `the security drones`;
+					if (V.currentUpgrade.type === "attack") {
+						V.droneUpgrades.attack++;
+					} else if (V.currentUpgrade.type === "defense") {
+						V.droneUpgrades.defense++;
+					} else if (V.currentUpgrade.type === "hp") {
+						V.droneUpgrades.hp++;
+					}
+				} else {
+					r += `all human troops`;
+					if (V.currentUpgrade.type === "attack") {
+						V.humanUpgrade.attack++;
+					} else if (V.currentUpgrade.type === "defense") {
+						V.humanUpgrade.defense++;
+					} else if (V.currentUpgrade.type === "hp") {
+						V.humanUpgrade.hp++;
+					} else if (V.currentUpgrade.type === "morale") {
+						V.humanUpgrade.morale += 10;
+					} else if (V.currentUpgrade.type === "attackAndDefense") {
+						V.humanUpgrade.attack++;
+						V.humanUpgrade.defense++;
+					} else if (V.currentUpgrade.type === "hpAndMorale") {
+						V.humanUpgrade.hp++;
+						V.humanUpgrade.morale += 10;
+					} else if (V.currentUpgrade.type === "all") {
+						V.humanUpgrade.attack++;
+						V.humanUpgrade.defense++;
+						V.humanUpgrade.hp++;
+						V.humanUpgrade.morale += 10;
+					}
+				}
+				delete V.currentUpgrade.name;
+				delete V.currentUpgrade.type;
+				V.currentUpgrade.unit = -1;
+				delete V.currentUpgrade.time;
+				r += `in the following days.`;
+				App.SecExp.Check.baseStats();
+				V.completedUpgrades.push(V.currentUpgrade.ID);
+			} else {
+				r += `It will be finished in `;
+				if (V.currentUpgrade.time === 1) {
+					r += `one week`;
+				} else {
+					r += `${V.currentUpgrade.time} weeks.`;
+				}
+			}
+			r += `\n`;
+			return r;
+		}
+	} // Closes security report funtion.
+
+	function authority() {
+		const V = State.variables; let r = ``;
+		if (V.useTabs === 0) {
+			r += `__Authority__`;
+		}
+		r += `\nYour authority is `;
+		if (V.SecExp.core.authority > 19500) {
+			r += `nearly absolute. The arcology is yours to command as it pleases you.`;
+		} else if (V.SecExp.core.authority > 15000) {
+			r += `extremely high. There's little you cannot do within the walls of your arcology.`;
+		} else if (V.SecExp.core.authority > 10000) {
+			r += `high. You command respect and fear in equal measure.`;
+		} else if (V.SecExp.core.authority > 5000) {
+			r += `moderate. You command some respect from your citizens.`;
+		} else {
+			r += `low. You command no respect or fear from your citizens.`;
+		}
+
+		let authGrowth = 0;
+
+		if (V.PC.career === "wealth") {
+			r += `As part of the idle rich, you were used to having obedience coming naturally to you. Now you find it harder to maintain authority over the arcology.`;
+			authGrowth -= (10 * jsRandom(5, 15));
+		} else if (V.PC.career === "slaver") {
+			r += `Your past as a slaver helps you assert your authority over the arcology.`;
+			authGrowth += (10 * jsRandom(5, 15));
+		} else if (V.PC.career === "escort") {
+			r += `Given your past career as an escort, you find it hard to assert your authority over the arcology and its inhabitants.`;
+			authGrowth -= (10 * jsRandom(5, 15));
+		} else if (V.PC.career === "servant") {
+			r += `Given your past career as a servant, you find it hard to assert your authority over the arcology and its inhabitants.`;
+			authGrowth -= (10 * jsRandom(5, 15));
+		} else if (V.PC.career === "BlackHat") {
+			r += `Given your past career as a (rather questionable) incursion specialist, you find it hard to assert your authority over the arcology and its inhabitants, despite what you may know about them.`;
+			authGrowth -= (10 * jsRandom(5, 15));
+		} else if (V.PC.career === "gang") {
+			r += `Given your past life as a gang leader, you find it easier to assert your authority over the arcology and its inhabitants.`;
+			authGrowth += (10 * jsRandom(5, 15));
+		}
+
+		if (V.rep >= 19500) {
+			r += `Your legend is so well known that your mere presence commands respect and obedience, increasing your authority.`;
+			authGrowth += (10 * jsRandom(10, 20));
+		} else if (V.rep >= 15000) {
+			r += `Your reputation is so high that your mere presence commands respect, increasing your authority.`;
+			authGrowth += (10 * jsRandom(5, 15));
+		} else if (V.rep >= 10000) {
+			r += `Your reputation is high enough that your presence commands some respect, increasing your authority.`;
+			authGrowth += (10 * jsRandom(2, 8));
+		}
+
+		if (V.SecExp.security.cap >= 90) {
+			r += `Your arcology is incredibly secure and your citizens know quite well who to thank, greatly increasing your authority.`;
+			authGrowth += (10 * jsRandom(10, 20));
+		} else if (V.SecExp.security.cap >= 70) {
+			r += `Your arcology is really secure and your citizens know quite well who to thank, increasing your authority.`;
+			authGrowth += (10 * jsRandom(5, 15));
+		} else if (V.SecExp.security.cap >= 50) {
+			r += `Your arcology is quite secure and your citizens know who to thank, increasing your authority.`;
+			authGrowth += (10 * jsRandom(2, 8));
+		}
+
+		if (V.SecExp.core.crimeLow >= 90) {
+			r += `The all powerful criminal organizations controlling the arcology have a very easy time undermining your authority.`;
+			authGrowth -= (10 * jsRandom(10, 20));
+		} else if (V.SecExp.core.crimeLow >= 70) {
+			r += `Crime is king in the arcology, powerful criminals have a very easy time undermining your authority.`;
+			authGrowth -= (10 * jsRandom(5, 15));
+		} else if (V.SecExp.core.crimeLow >= 50) {
+		r += `	Criminal organizations have a strong foothold in the arcology, their activities undermine your authority.`;
+			authGrowth -= (10 * jsRandom(2, 8));
+		}
+
+		if (V.averageDevotion >= 50 && V.averageTrust >= 50) {
+			r += `The high devotion and trust of your slaves speak eloquently of your leadership capabilities, helping your authority grow.`;
+			authGrowth += (5 * ((V.averageDevotion + V.averageTrust) / 10));
+		} else if (V.averageDevotion >= 50) {
+			r += `The high devotion of your slaves speaks eloquently of your leadership capabilities, helping your authority grow.`;
+			authGrowth += (5 * (V.averageDevotion / 10));
+		} else if (V.averageTrust >= 50) {
+			r += `The high trust of your slaves speaks eloquently of your leadership capabilities, helping your authority grow.`;
+			authGrowth += (5 * (V.averageTrust / 10));
+		}
+
+		if (V.arcologies[0].ownership >= 90) {
+			r += `You own so much of the arcology that your authority quickly increases.`;
+			authGrowth += (5 * Math.trunc(V.arcologies[0].ownership / 10));
+		} else if (V.arcologies[0].ownership >= 70) {
+			r += `You own a big part of the arcology, causing your authority to increase.`;
+			authGrowth += (5 * Math.trunc(V.arcologies[0].ownership / 10));
+		} else if (V.arcologies[0].ownership >= 50) {
+			r += `You own the majority of the arcology, causing your authority to slowly increase.`;
+			authGrowth += (5 * Math.trunc(V.arcologies[0].ownership / 10));
+		} else {
+			r += `Your low ownership of the arcology causes your authority to decrease.`;
+			authGrowth -= (5 * Math.trunc(V.arcologies[0].ownership / 10));
+		}
+
+		if (V.activeUnits >= 9) {
+			r += `Your military is massive; commanding so many troops greatly increases your authority.`;
+			authGrowth += (12 * V.activeUnits);
+		} else if (V.activeUnits >= 7) {
+			r += `Your military is huge; commanding such a number of soldiers increases your authority.`;
+			authGrowth += (12 * V.activeUnits);
+		} else if (V.activeUnits >= 4) {
+			r += `Your military is at a decent size; commanding a small army increases your authority.`;
+			authGrowth += (12 * V.activeUnits);
+		}
+
+		if (V.SF.Toggle && V.SF.Active >= 1 && V.SF.Size > 10) {
+		r += `Having a powerful special force increases your authority.`;
+			authGrowth += (V.SF.Size/10);
+		}
+
+		if (V.arcologies[0].FSChattelReligionist >= 90) {
+			r += `Religious organizations have a tight grip on the minds of your residents and their dogma greatly helps your authority grow.`;
+			authGrowth += V.arcologies[0].FSChattelReligionist;
+		} else if (V.arcologies[0].FSChattelReligionist >= 50) {
+			r += `Religious organizations have a tight grip on the minds of your residents and their dogma helps your authority grow.`;
+			authGrowth += V.arcologies[0].FSChattelReligionist;
+		}
+
+		if (V.arcologies[0].FSRestart >= 90) {
+			r += `The arcology's society is extremely stratified. The reliance on the Societal Elite by the lower classes greatly increases your reputation.`;
+			authGrowth += V.arcologies[0].FSRestart;
+		} else if (V.arcologies[0].FSRestart >= 50) {
+			r += `The arcology's society is very stratified. The reliance on the Societal Elite by the lower classes increases your reputation.`;
+			authGrowth += V.arcologies[0].FSRestart;
+		}
+
+		if (V.arcologies[0].FSPaternalist >= 90) {
+			r += `Your extremely paternalistic society has the unfortunate side effects of spreading dangerous ideals in the arcology, greatly damaging your authority.`;
+			authGrowth -= Math.clamp(V.arcologies[0].FSPaternalist, 0, 100);
+		} else if (V.arcologies[0].FSPaternalist >= 50) {
+			r += `Your paternalistic society has the unfortunate side effects of spreading dangerous ideals in the arcology, damaging your authority.`;
+			authGrowth -= Math.clamp(V.arcologies[0].FSPaternalist, 0, 100);
+		}
+
+		if (V.arcologies[0].FSNull >= 90) {
+			r += `Extreme cultural openness allows dangerous ideas to spread in your arcology, greatly damaging your reputation.`;
+			authGrowth -= V.arcologies[0].FSNull;
+		} else if (V.arcologies[0].FSNull >= 50) {
+			r += `Mild cultural openness allows dangerous ideas to spread in your arcology, damaging your reputation.`;
+			authGrowth -= V.arcologies[0].FSNull;
+		}
+
+		if (V.miniTruth >= 1) {
+			r += `Your authenticity department works tirelessly to impose your authority in all of the arcology.`;
+			authGrowth += (15 * V.miniTruth);
+		}
+
+		if (V.secretService >= 1) {
+			r += `Your secret services constantly keep under surveillance any potential threat, intervening when necessary. Rumors of the secretive security service and mysterious disappearances make your authority increase.`;
+			authGrowth += (15 * V.secretService);
+		}
+
+		if (V.SecExp.edicts.upkeep > 0) {
+			r += `Some of your authority is spent maintaining your edicts.`;
+			authGrowth -= V.SecExp.edicts.upkeep;
+		}
+
+		r += `This week `;
+		if (authGrowth > 0) {
+			r += `<span class='green'>authority has increased.</span> `;
+		} else if (authGrowth === 0) {
+			r += `<span class='yellow'>authority did not change.</span> `;
+		} else {
+			r += `<span class='red'>authority has decreased.</span> `;
+		}
+
+		V.SecExp.core.authority += authGrowth;
+		V.SecExp.core.authority = Math.trunc(Math.clamp(V.SecExp.core.authority, 0, 20000));
+
+		if (V.SecExp.settings.rebellion.enabled === 1) {
+			r += `\n\n`; App.SecExp.Check.gen('rebellion');
+		}
+		return r;
+	} // Closes authority report funtion.
+
+	function rebellionInit() {
+		const V = State.variables; let r = ``;
+		r += `In the end it happened, the `;
+		if (V.SecExp.conflict.type === 0) {
+			r += `slaves`;
+		} else if (V.SecExp.conflict.type === 1) {
+			r += `citizens`;
+		}
+		r += `of your arcology dared took up arms and rose up against their betters. Your penthouse is flooded with reports from all over the arcology of small skirmishes between the rioting residents and the security forces.`;
+		r += `It appears <strong>$(num(Math.trunc(V.SecExp.conflict.attacker.troops))}</strong> rebels are in the streets right now, building barricades and `;
+		if (V.SecExp.conflict.type === 0) {
+			r += `freeing their peers`;
+		} else if (V.SecExp.conflict.type === 1) {
+			r += `destroying your property`;
+		}
+		r += `. They are`;
+		return r;
+	}
+
+	function enemyTroops() {
+		const V = State.variables; let r = ``;
+		if (V.SecExp.conflict.attacker.equip <= 0) {
+			r += `<strong>poorly armed</strong>.`;
+			if(V.SecExp.conflict.type >= 2) {
+				r += ` Old rusty small arms are the norm with just a few barely working civilian vehicles.`;
+			}
+		} else if (V.SecExp.conflict.attacker.equip === 1) {
+			r += `<strong>lightly armed</strong>`;
+			if(V.SecExp.conflict.type >= 2) {
+				r += `, mostly wth small arms and some repurposed civilian vehicles with scattered machine gun support. There's no sign of heavy vehicles, artillery or aircraft.`;
+			} else {
+				r += `.`;
+			}
+		} else if (V.SecExp.conflict.attacker.equip === 2) {
+			r += `<strong>decently armed</strong>.`;
+			if(V.SecExp.conflict.type >= 2) {
+				r += ` with good quality small arms, machine guns and a few mortars. There appear to be some heavy military vehicles coming as well.`;
+			} else {
+				r += `.`;
+			}
+		} else if (V.SecExp.conflict.attacker.equip === 3) {
+			r += `<strong>well armed</strong>.`;
+			if(V.SecExp.conflict.type >= 2) {
+				r += ` with high quality small arms, snipers, demolitions teams, heavy duty machine guns and mortars. Heavy military vehicles are numerous and a few artillery pieces are accompanying the detachment.`;
+			}
+		} else if (V.SecExp.conflict.attacker.equip >= 4) {
+			r += `<strong>extremely well armed</strong>.`;
+			if(V.SecExp.conflict.type >= 2) {
+				r += `with excellent small arms and specialized teams with heavy duty infantry support weapons. Heavy presence of armored military vehicles, artillery pieces and even some attack helicopters.`;
+			} else {
+				r += `.`;
+			}
+		}
+	}
+
+	function conflictEnd() {
+		const V = State.variables; let r = ``;
+		let day = V.day + random(0, 7);
+		let month = V.month;
+		let year = V.year;
+		switch (month) {
+		case "January":
+			if (day > 31) {
+				day -= 31; month = "February";
+			}
+			break;
+		case "February":
+			if (day > 28) {
+				day -= 28; month = "March";
+			}
+			break;
+		case "March":
+			if (day > 31) {
+				day -= 31; month = "April";
+			}
+			break;
+		case "April":
+			if (day > 30) {
+				day -= 30; month = "May";
+			}
+			break;
+		case "May":
+			if (day > 31) {
+				day -= 31; month = "June";
+			}
+			break;
+		case "June":
+			if (day > 30) {
+				day -= 30; month = "July";
+			}
+			break;
+		case "July":
+			if (day > 31) {
+				day -= 31; month = "August";
+			}
+			break;
+		case "August":
+			if (day > 31) {
+				day -= 31; month = "September";
+			}
+			break;
+		case "September":
+			if (day > 30) {
+				day -= 30; month = "October";
+			}
+			break;
+		case "October":
+			if (day > 31) {
+				day -= 31; month = "November";
+			}
+			break;
+		case "November":
+			if (day > 30) {
+				day -= 30; month = "December";
+			}
+			break;
+		default:
+			if (day > 31) {
+				day -= 31; month = "January"; year += 1;
+			}
+		}
+		r += `Today, the ${day} of ${month} ${year}, our arcology was `;
+
+		if(V.SecExp.conflict.type >= 2) {
+			r += `attacked by a`;
+			if(V.SecExp.conflict.battle.event.attacker === "raiders") {
+				r += ` band of wild raiders`;
+			} else if (V.SecExp.conflict.battle.event.attacker === "free city") {
+				r += ` contingent of mercenaries hired by a competing free city`;
+			} else if (V.SecExp.conflict.battle.event.attacker === "freedom fighters") {
+				r += ` group of freedom fighters bent on the destruction of the institution of slavery`;
+			} else if (V.SecExp.conflict.battle.event.attacker === "old world") {
+				r += `n old world nation boasting a misplaced sense of superiority`;
+			}
+			r += `, ${num(Math.trunc(V.SecExp.conflict.battle.event.attacker.troops))} men strong.`;
+		} else if (V.SecExp.conflict.type < 2) {
+			r += `inflamed by the fires of rebellion`;
+		}
+
+		r += `, ${num(Math.trunc(V.SecExp.conflict.battle.event.attacker.troops))} `;
+		if(V.SecExp.conflict.type >= 2) {
+			r += `men strong.`;
+		} else {
+			r += `rebels from all over the structure dared rise up `;
+			if (V.SecExp.conflict.type < 2) {
+				r += `against their owners and conquer their freedom through blood.`;
+			} else {
+				r += `to dethrone their arcology owner.`;
+			}
+		}
+		return r;
+	}
+})(); // Closes report funtion.
+
+App.SecExp.unit = (function() {
+	return {
+		dec:description,
+		gen:generateNew,
+		rm:remove, // App.SecExp.removeUnits
+		idGen:generateUnitID,
+	};
+
+	function description(input) {
+		const V = State.variables; let r = ``;
+		if(jsDef(input.active)) {
+		 r += `<strong>${input.platoonName}</strong>`;
+		 if(jsDef(input.battlesFought)) {
+		  if(input.battlesFought > 1) {
+		   r += `participated in ${input.battlesFought} battles and is ready to face the enemy once more at your command`;
+		  } else if (input.battlesFought === 1) {
+		   r += `is ready to face the enemy once more at your command`;
+		  } else {
+		   r += `is ready to face the enemy in battle`;
+		  }
+		 }
+
+		 r += `.\nIts ${input.troops} `;
+		 if(input !== "Bots") {
+		 	r += `men and women are `; 
+				if(input === "Militia") {
+					r += `all proud citizens of your arcology, willing to put their lives on the line to protect their home.`;
+				} else if (input === "Slaves") {
+					r += `slaves in your possession, tasked with the protection of their owner and their arcology.`;
+				} else if (input === "Mercs") {
+				r += `mercenaries contracted to defend the arcology against external threats.`;
+				}
+			} else {
+			 r += `are assembled in an ordered line in front of you, absolutely silent and ready to receive their orders.`;
+			}
+
+		 if(input.troops < input.maxTroops) {
+		  r += `The unit is not at its full strength of $args[0].maxTroops operatives.`;
+		 }
+		 
+		 if(input !== "Bots") {
+		  if(input.equip === 0) {
+		   r += `They are issued with simple, yet effective equipment: firearms, a few explosives and standard uniforms, nothing more.`;
+		  } else if (input.equip === 1) {
+		   r += `They are issued with good, modern equipment: firearms, explosives and a few specialized weapons like sniper rifles and machine guns. They also carry simple body armor.`;
+		  } else if (input.equip === 2) {
+		   r += `They are issued with excellent, high tech equipment: modern firearms, explosives, specialized weaponry and modern body armor. They are also issued with modern instruments like night vision and portable radars.`;
+		  } else {
+		   r += `They are equipped with the best the modern world has to offer: modern firearms, explosives, specialized weaponry, experimental railguns, adaptive body armor and high tech recon equipment.`;
+		  }
+		 } else {
+		  if(input.equip === 0) {
+		   r += `They are equipped with light weaponry, mainly anti-riot nonlethal weapons. Not particularly effective in battle.`;
+		  } else if (input.equip === 1) {
+		   r += `They are equipped with light firearms, not an overwhelming amount of firepower, but with their mobility good enough to be effective.`;
+		  } else if (input.equip === 2) {
+		   r += `They are equipped with powerful, modern firearms and simple armor mounted around their frames. They do not make for a pretty sight, but on the battlefield they are a dangerous weapon.`;
+		  } else {
+		   r += `They are equipped with high energy railguns and adaptive armor. They are a formidable force on the battlefield, even for experienced soldiers.`;
+		  }
+		 }
+		 
+		 if(input !== "Bots") {
+		  if(input.training <= 33) {
+		   r += `They lack the experience to be considered professionals, but `;
+		  if (input === "Militia") {
+		   r += `their eagerness to defend the arcology makes up for it.`;
+		  	} else if (input === "Slaves") {
+		  	 r += `their eagerness to prove themselves makes up for it.`;
+		  	} else if (input === "Mercs") {
+		    r += `they're trained more than enough to still be an effective unit.`;
+		   }
+		  } else if (input.training <= 66) {
+		   r += `They have trained `;
+		   if (input.battlesFought > 0) {
+		    r += `and fought `;
+		   }
+		   r += `enough to be considered disciplined, professional soldiers, ready to face the battlefield.`;
+		  } else {
+		   r += `They are consummate veterans, with a wealth of experience and perfectly trained. On the battlefield they are a well oiled war machine capable of facing pretty much anything.`;
+		  }
+		  
+		  if(input.loyalty < 10) {
+		   r += `The unit is extremely disloyal. Careful monitoring of their activities and relationships should be implemented.`;
+		  } else if (input.loyalty < 33) {
+		   r += `Their loyalty is low. Careful monitoring of their activities and relationships is advised.`;
+		  } else if (input.loyalty < 66) {
+		   r += `Their loyalty is not as high as it can be, but they are not actively working against their arcology owner.`;
+		  } else if (input.loyalty < 90) {
+		   r += `Their loyalty is high and strong. The likelihood of this unit betraying the arcology is low to non-existent.`;
+		  } else {
+		   r += `The unit is fanatically loyal. They would prefer death over betrayal.`;
+		  }
+		  
+		  if(jsDef(input.cyber)) {
+		   r += `The soldiers of the unit have been enhanced with numerous cyberaugmentations which greatly increase their raw power.`;
+		  }
+		  if(jsDef(input.medics)) {
+		   r += `The unit has a dedicated squad of medics that will follow them in battle.`;
+		  }
+		  if(V.SF.Toggle && V.F.Active >= 1 && jsDef(input.SF)) {
+		   r += `The unit has attached advisors from ${V.SF.Lower} that will help the squad remain tactically aware and active.`;
+		  }
+		 }
+		} else {
+		 r += `${input.platoonName} lost too many operatives`;
+		 if(jsDef(input.battlesFought)) {
+		  r += ` in the ${input.battlesFought} it fought`;
+		 }
+		 r += ` and can no longer be considered a unit at all.`;
+		}
+	}
+
+	function generateNew(input) {
+		const V = State.variables;
+		if (V.SecExp.battle[input] === undefined) {
+		 V.SecExp.battle[input] = {created:0, squads:[]};
+		 if (input !== "Bots") {
+		  V.SecExp.battle[input].employed = 0;
+		  V.SecExp.battle[input].total = 0;
+		  V.SecExp.battle[input].casualties = 0;
+		 } else if (input !== "Slaves") {
+		  V.SecExp.battle[input].free = 0;
+		 } else if (input === "Mercs") {
+		  V.SecExp.battle[input].loyalty = 0;
+		  if (V.mercenaries === 1) {
+		   V.SecExp.battle[input].free = jsRandom(5, 20);
+		  } else if (V.mercenaries > 1) {
+		   V.SecExp.battle[input].free = jsRandom(10, 30);
+		  }
+		 }
+		}
+		
+		newUnit = {troops:30,maxTroops:50,equip:0, active:1, battlesFought:0};
+		newUnit.ID = V.SecExp.battle[input].squads.length++;
+		let text;
+		switch(input) {
+		case "Bots":
+		 text += `security drone`;
+		 newUnit.troops = 50;
+			newUnit.maxTroops = 80;
+			break;
+		case "Militia":
+		 text += `citizens`;
+		 break;
+		case "Mercs":
+		 text += `mercenary`;
+		 break;
+		case "Slaves":
+		 text += `slave`;
+		 break;
+		}
+		 
+		if (input !== "Bots") {
+			newUnit.loyalty = 0;
+			newUnit.loyalty.training = 0;
+		}
+		newUnit.platoonName = `${ordinalSuffix(V.SecExp.battle.input.created++)} ${text} platoon`;
+		
+		V.SecExp.battle[input].squads.push(newUnit);
+		if(jsDef(V.SecExp.battle[input].free)) {
+		 V.SecExp.battle[input].free -= newUnit.troops;
+		}
+		if(jsDef(V.SecExp.battle[input].employed)) {
+		 V.SecExp.battle[input].employed += newUnit.troops;
+		}
+		
+		V.activeUnits++;
+					// loyalty: jsRandom(40,60)
+		if (input === '') {
+						newUnit.loyalty=jsRandom();
+		} else if (input === '') {
+						newUnit.loyalty=jsRandom();
+		} else if (input === '') {
+						newUnit.loyalty=jsRandom();
+		} else if (input === '') {
+						newUnit.loyalty=jsRandom();
+		} else if (input === '') {
+						newUnit.loyalty=jsRandom();
+		}
+	}
+
+	function remove(Unit) {
+		const V = State.variables;
+		// args[0] is the array of IDs of units to be eliminated
+		let newTarget=[];
+		for (let i=0; i < V.rawArray.length; i++) {
+						if ( !(V.args[0].includes(rebelArray[i].ID)) ){
+										newTarget.push(rawArray[i]);
+						}
+		}
+		V.rawArray = newTarget;
+	}
+
+	function generateUnitID(input) {
+		const V = State.variables;
+		let newID = 0;
+		for(let i = 0; i < V.SecExp.battle[input].squads.length; i++) {
+			if (V.SecExp.battle[input].squads[i].ID >= newID) {
+				newID = V.SecExp.battle[input].squads[i].ID + 1;
+			}
+		}
+		// V.args[0].ID = newID;
+	}
+})();
+
+App.SecExp.encyclopedia = (function() {
+	return {
+		main:main,
+		battles:battles,
+	};
+
+	function main() {
+		let r = ``;
+		r +=`The Security Expansion Mod
+		<hr>
+		''Note: The Security Expansion mod is an optional mod. It can be switched freely on and off from the game option menu or at the start of the game.''
+
+		The world of Free Cities is not a forgiving one, those who do not seek to dominate it, will inevitably be dominated themselves.
+		Good rulers need to keep control of its realm, if they want to have long and prosperous lives.
+		You will have to manage your <span class='darkviolet'>authority</span> inside the walls of your arcology, you will have to keep it <span class='deepskyblue'>secure</span> and keep in check <span class='orangered'>crime</span> and rivals alike, you will have to take up arms and command your troops against those who defy your rule.
+
+			Statistics:
+			<span class='darkviolet'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Authority</strong>:</span>
+			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Representing the power the player holds over the arcology. If <span class='green'>[[reputation|Encyclopedia][$encyclopedia = "Arcologies and Reputation"]]</span> is how well the protagonist is known, <span class='darkviolet'>authority</span> is how much is feared or respected.
+			Authority influences many things, but it is mainly used to enact edicts, who, similarly to policies, allow to shape the sociopolitical profile of your arcology. Like <span class='green'>reputation,</span> <span class='darkviolet'>authority</span> has a maximum of ${num(20000)}.
+			<span class='deepskyblue'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Security</strong>:</span>
+			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Representing how safe the arcology is, how likely it is for a citizen to get stabbed, killed or simply mugged in the streets as well as wider concerns like
+			dangerous political organizations, terrorist groups and more. It influences many things, but its main task is to combat <span class='orangered'>crime.</span>
+			<span class='orangered'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Crime</strong>:</span>
+			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Representing the accumulated power of criminals in the arcology. Rather than representing low level criminal activity, better represented by <span class='deepskyblue'>security</span> (or better lack of), but
+			the influence, organization and reach of criminal organizations, be it classic mafia families or high tech hacker groups. Do not let their power run rampant or you'll find your treasury emptier and emptier.
+			Both <span class='deepskyblue'>security</span> and <span class='orangered'>crime</span> are displayed a 0-100% scale.
+
+			The battles:
+			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Arcologies are sturdy structures, difficult to assault without preparation or overwhelming numbers. [["Security drones"|Encyclopedia][$encyclopedia = "Security Drones"]] can easily handle small incursions and a few well placed mercenary squads can handle the rest.
+			However, in order for Free Cities to survive they need many things, many of which are expensive. If you want your arcology to survive the tide of times, you'd better prepare your soldiers and defend the vital lifelines that connect your arcology with the rest of the world.
+			For a detailed outlook of how battles work see the relative page.
+
+			Buildings:
+			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>The Barracks</strong>: This is where troops can be prepared and organized to respond to threats encroaching on the arcology's territory.
+			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>The Security HQ</strong>: This is where your security department will manage the <span class='deepskyblue'>security</span> of the arcology.
+			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>The Propaganda Hub</strong>: This is where your propaganda department will expand and deepen your <span class='darkviolet'>authority</span> over the arcology.
+			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>The TransportHub</strong>: This is where trade happens. Mainly intended as a counter to prosperity loss events.
+			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>The RiotControlCenter</strong>: Fairly self explanatory, will help you manage rebellions.
+		<hr>`;
+		return r;
+	}
+
+	function battles() {
+		let
+		r =`Battles in the Security Expansion Mod
+		<hr>
+		With the Security Expansion mod enabled there is a small chance each week that an attacking force will be approaching the arcology. Their motives may vary, but their intentions are clear: hit you where it hurts.
+		You arcology will start being the subject of incursions only when the [["security drones"|Encyclopedia][$encyclopedia = "Security Drones"]] upgrade has been installed.
+
+		Unit types:
+			<strong>Slave Units</strong>: recruitable from your stockpile of menial slaves. They are cheap, easy to replace troops that will hold the line well enough.
+			Of the three they have the lowest base stats, but they have the advantage of being available from the beginning, have the lowest upkeep and can be replenished in any moment, provided enough cash is available.
+			<strong>Militia Units</strong>: recruitable only after a special edict is passed. Once the militia is announced recruitment laws will become available and recruits will present themselves to the barracks, waiting to be assigned to a unit.
+			Militia units are slightly stronger than slave units, but their manpower is limited by the laws enacted and the citizen population.
+			<strong>Mercenary Units</strong>: installing a permanent platoon in the arcology is a great defensive tool, but if you need muscle outside the walls of your dominion you'll need to hire more.
+			Mercenary units have the highest base stats (in almost all categories), but are also only available if the arcology is garrisoned by the mercenary platoon, are fairly slow to replenish and have the highest upkeep.
+			Once garrisoned by the mercenary platoon, more mercenaries will slowly make their way to the arcology. You have little control over their number other than increasing your arcology prosperity or your reputation.
+			<strong>The Security Drones</strong>: The security drones are a special unit. You cannot field more than one unit of this type and their stats (with the exception of their very high morale) are fairly low, however they cheap to replenish and have a low maintenance cost. They do not accumulate experience and are not affected by morale modifiers (for better or worse).
+
+		Units statistics:
+			<strong>Troops</strong>: The number of active combatants the unit can field. If it reaches zero the unit will cease to be considered active. It may be reformed as a new unit without losing the upgrades given to it, but experience is lost.
+			<strong>Maximum Troops</strong>: The maximum number of combatants the unit can field. You can increase this number through upgrade.
+			<strong>Equipment</strong>: The quality of equipment given to the unit. Each level of equipment will increase attack and defense values of the unit by 15%.
+			<strong>Experience</strong>: The quality of training provide/acquired in battle by the unit. Experience is a 0-100 scale with increasingly high bonuses to attack, defense and morale of the unit, to a maximum of 50% at 100 experience.
+			<strong>Medical support</strong>: Attaching medical support to the unit will decrease the amount of casualties the unit takes in battle.
+
+		Battles:
+			Battles are fought automatically, but you can control various fundamental parameters, here are the most important statistics:
+			<strong>Readiness</strong>: readiness represents how prepared the arcology is to face an attack. For every point of readiness you can field two units. You can find upgrades for in in the security HQ.
+			<strong>Tactics</strong>: Tactics are the chosen plan of action. You should carefully choose one depending on the terrain, type of enemy and leader choice, because if applied successfully they can sway a battle in your favor or doom your troops.
+			<strong>Terrain</strong>: Terrain has a great influence on everything, but mainly on the effectiveness of the tactic chosen.
+			<strong>Leader</strong>: The leader is who will command the combined troops in the field. Each type of leader has its bonuses and maluses.
+
+		Leaders: <<setAssistantPronouns>>
+			<strong>The Assistant</strong>: The assistant can lead the troops. _HisA performance will entirely depend on the computational power _heA has available. Human soldiers will be not happy to be lead by a computer however and will fight with less ardor, unless your own reputation or authority is high enough.
+			<strong>The Arcology Owner</strong>: You can join the fray yourself. Your performance will depend greatly on your warfare skill and your past. The troops will react to your presence depending on your social standing and your past as well.
+				Do note however there is the possibility of getting wounded, which makes you unable to focus on any task for a few weeks.
+			<strong>Your Bodyguard</strong>: Your bodyguard can guide the troops. Their performance will greatly depend on their intelligence and past. Slaves will be happy to be lead by one of them, but militia and mercenaries will not, unless your own authority is high enough to make up for the fact they are being lead by a slave.
+			<strong>Your Head Girl</strong>: Your Head Girl can guide the troops, and will act very similarly to the bodyguard in battle. Be aware that both slaves run the risk of getting wounded, potentially with grave wounds like blindness or limb loss.
+			<strong>An Outstanding Citizen</strong>: One of your citizens can take the leading role. Their performance will be average; however the militia will be pleased to be guided by one of them.
+			To allow slaves to lead troops a specific edict will have to be enacted.
+			<strong>A Mercenary Officer</strong>: One of the mercenary commanders can take the lead. Their performance will be above average and mercenary units will be more confident, knowing they're being lead by someone with experience.`;
+
+			if (State.variables.SF.Toggle === 1 && State.variables.SF.Active >= 1) {
+				r += `\n<strong>The Colonel</strong>: The special force's colonel can take the lead. Her performance will be above average and mercenary (in addition to hers obviously) units will be more confident, knowing they're being lead by someone with experience. Her tactics have a higher chance of success along with better offense and defense.`;
+			}
+		r += `<hr>`;
+		return r;
+	}
+})();
\ No newline at end of file
diff --git a/src/SecExp/secExpSmilingMan.tw b/src/SecExp/secExpSmilingMan.tw
index 7953ec802c9..cc57acccfb9 100644
--- a/src/SecExp/secExpSmilingMan.tw
+++ b/src/SecExp/secExpSmilingMan.tw
@@ -168,7 +168,7 @@
 	<<run repX(($rep * 0.6)-$rep, "event")>>
 
 	<<if $arcologies[0].ownership >= 60>>
-		<<if $authority <= 10000>>
+		<<if $SecExp.core.authority <= 10000>>
 			<<for _i = 1; _i < $sectors.length; _i++>>
 				<<if $sectors[_i].ownership == 1>>
 					<<if $sectors[_i].type != "Brothel">>
@@ -201,8 +201,8 @@
 		Your cold storage facility has ensured that the Smiling Man's destruction of the primary archives was unable to damage the security of your arcology.
 	<<elseif $secUpgrades.coldstorage == 0>>
 		Your security department sees its archives butchered by the Smiling Man. Almost all data on criminals, citizens, and operations are lost. The @@.red;security of the arcology is greatly reduced.@@ Criminals, on the other hand, with their past erased, cannot wait to join this new world, so @@.red;crime will inevitably increase.@@
-		<<set $security = Math.clamp($security * 0.2,0,100)>>
-		<<set $crime = Math.clamp($crime * 1.5, 20,100)>>
+		<<set $SecExp.security.cap = Math.clamp($SecExp.security.cap * 0.2,0,100)>>
+		<<set $SecExp.core.crimeLow = Math.clamp($SecExp.core.crimeLow * 1.5, 20,100)>>
 	<</if>>
 
 	<br>A short, meek man approaches you with a weak smile. "Not all is lost, <<= properTitle()>>. We have a lead on him — he is here, in $arcologies[0].name."
diff --git a/src/SecExp/secInit.tw b/src/SecExp/secInit.tw
index a0a61843951..3cfe2dfeb62 100644
--- a/src/SecExp/secInit.tw
+++ b/src/SecExp/secInit.tw
@@ -1,11 +1,7 @@
 :: secInit [nobr]
 
 /* base vars */
-<<set $authority = 0>>
-<<set $security = 30>>
-<<set $secRestPoint = 30>>
-<<set $crime = 30>>
-<<set $crimeCap = 100>>
+<<= App.SecExp.Check.general()>>
 <<set $readiness = 1>>
 <<set $recon = 0>>
 <<set $maxUnits = 6>>
diff --git a/src/SecExp/securityHQ.tw b/src/SecExp/securityHQ.tw
index c1aaa37d774..cdc0d7b6376 100644
--- a/src/SecExp/securityHQ.tw
+++ b/src/SecExp/securityHQ.tw
@@ -44,7 +44,7 @@ You have <span id="secHel"> <<print num($secMenials)>> </span> slaves working in
 			<<set _finalMaxCost = Math.trunc(_maxMenials*(_menialPrice+_menialBulkPremium))>>
 			[[(max)|securityHQ][$menials += Math.trunc(_maxMenials), $menialSupplyFactor -= Math.trunc(_maxMenials), cashX(-_finalMaxCost, "menialTransfer")]]
 		<</if>>
-		//Bulk transactions may require offering a premium.//
+		//Bulk transactions may require offering a premium. The remaining slaves will be more efficient in dealling with crime.//
 	<</if>>
 <</if>>
 <<if $menials > 0>>
@@ -204,48 +204,48 @@ You have <span id="secHel"> <<print num($secMenials)>> </span> slaves working in
 <br><br>
 
 /* security level and upgrades */
-Your security level (@@.deepskyblue;$security@@)
-<<if $security <= 20>>
+Your security level (@@.deepskyblue;$SecExp.security.cap@@)
+<<if $SecExp.security.cap <= 20>>
 	is dangerously low.
-<<elseif $security <= 40>>
+<<elseif $SecExp.security.cap <= 40>>
 	is low.
-<<elseif $security <= 60>>
+<<elseif $SecExp.security.cap <= 60>>
 	is decent.
-<<elseif $security <= 80>>
+<<elseif $SecExp.security.cap <= 80>>
 	is good.
 <<else>>
 	is great.
 <</if>>
-Considering the current upgrades the resting level for security is <<print $secRestPoint>>, while the effective maximum level is <<print Math.trunc($secRestPoint * (Math.clamp($secMenials,0,$reqMenials) / $reqMenials))>>.
+Considering the current upgrades the resting level for security is <<print $SecExp.security.low>>, while the effective maximum level is <<print Math.trunc($SecExp.security.low * (Math.clamp($secMenials,0,$reqMenials) / $reqMenials))>>.
 
 <br>
 <br>
 
 <<if $secUpgrades.nanoCams == 0>>
-	[[Install a nano-camera system |securityHQ][cashX(-Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.nanoCams = 1, $secRestPoint += 15, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep]]
-	<br>//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will raise rest point of security by 10 points, but will require 5 extra slaves in the headquarters and increases upkeep.//
+	[[Install a nano-camera system |securityHQ][cashX(-Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.nanoCams = 1, $SecExp.security.low += 15, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep]]
+	<br>//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will raise rest point of security by 10 points, but will require 5 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 <<else>>
 	You have installed all across the arcology closed circuit nano-cameras to keep the arcology under your watchful eye.
 <</if>>
 <br>
 <<if $secUpgrades.cyberBots == 0>>
-	[[Buy cybersecurity algorithms|securityHQ][cashX(-Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.cyberBots = 1, $secRestPoint += 15, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep]]
-	<br>//Costs <<print cashFormat(Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will raise rest point of security by 10 points, but will require 5 extra slaves in the headquarters and increases upkeep.//
+	[[Buy cybersecurity algorithms|securityHQ][cashX(-Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.cyberBots = 1, $SecExp.security.low += 15, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep]]
+	<br>//Costs <<print cashFormat(Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will raise rest point of security by 10 points, but will require 5 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 <<else>>
 	You have bought advanced cybersecurity algorithms that will defend your arcology against hack attempts or cyber frauds.
 <</if>>
 <br>
-<<if $authority > 10000>>
+<<if $SecExp.core.authority > 10000>>
 	<<if $secUpgrades.eyeScan == 0>>
-		[[Install invisible eye scanners|securityHQ][cashX(-Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.eyeScan = 1, $secRestPoint += 20, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep]]
-		<br>//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will raise rest point of security by 15 points, but will require 10 extra slaves in the headquarters and increases upkeep.//
+		[[Install invisible eye scanners|securityHQ][cashX(-Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.eyeScan = 1, $SecExp.security.low += 20, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep]]
+		<br>//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will raise rest point of security by 15 points, but will require 10 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 	<<else>>
 		You have installed numerous hidden eye scanners that accurately register the movements of everyone inside the arcology.
 	<</if>>
 	<br>
 	<<if $secUpgrades.cryptoAnalyzer == 0>>
-		[[Buy and install crypto analyzers|securityHQ][cashX(-Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.cryptoAnalyzer = 1, $secRestPoint += 20, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep]]
-		<br>//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will raise rest point of security by 15 points, but will require 10 extra slaves in the headquarters and increases upkeep.//
+		[[Buy and install crypto analyzers|securityHQ][cashX(-Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.cryptoAnalyzer = 1, $SecExp.security.low += 20, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep]]
+		<br>//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will raise rest point of security by 15 points, but will require 10 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 	<<else>>
 		You have bought and employed sophisticated crypto analyzing software to accurately track and archive every financial movement or transaction made inside the walls of your arcology.
 	<</if>>
@@ -257,48 +257,48 @@ Considering the current upgrades the resting level for security is <<print $secR
 <br>
 
 /* crime level and upgrades */
-Your crime level (@@.orangered;$crime@@)
-<<if $crime <= 20>>
+Your crime level (@@.orangered;$SecExp.core.crimeLow@@)
+<<if $SecExp.core.crimeLow <= 20>>
 	is very low.
-<<elseif $crime <= $upgradeUpkeep>>
+<<elseif $SecExp.core.crimeLow <= $upgradeUpkeep>>
 	is low.
-<<elseif $crime <= 60>>
+<<elseif $SecExp.core.crimeLow <= 60>>
 	is average.
-<<elseif $crime <= $upgradeUpkeep>>
+<<elseif $SecExp.core.crimeLow <= $upgradeUpkeep>>
 	is high.
 <<else>>
 	is extremely high.
 <</if>>
-Considering the current upgrades the maximum level of crime is <<print $crimeCap>>, while the effective maximum level is <<print Math.trunc(Math.clamp($crimeCap + ($crimeCap - $crimeCap * ($secMenials / $reqMenials)),0,100))>>.
+Considering the current upgrades the maximum level of crime is <<print $SecExp.core.crimeCap>>, while the effective maximum level is <<print Math.trunc(Math.clamp($SecExp.core.crimeCap + ($SecExp.core.crimeCap - $SecExp.core.crimeCap * ($secMenials / $reqMenials)),0,100))>>.
 
 <br>
 <br>
 
 <<if $crimeUpgrades.advForensic == 0>>
-	[[Install advanced forensic equipment|securityHQ][cashX(-Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $crimeUpgrades.advForensic = 1, $crimeCap -= 10, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-	<br>//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will bring down the crime level cap by 10 points, but will require 5 extra slaves in the headquarters and increases upkeep.//
+	[[Install advanced forensic equipment|securityHQ][cashX(-Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $crimeUpgrades.advForensic = 1, $SecExp.core.crimeCap -= 10, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
+	<br>//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will bring down the crime level cap by 10 points, but will require 5 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 <<else>>
 	You have installed advanced forensic equipment, able to extract every bit of precious information from any clue.
 <</if>>
 <br>
 <<if $crimeUpgrades.autoArchive == 0>>
-	[[Install auto-curating archiver|securityHQ][cashX(-Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $crimeUpgrades.autoArchive = 1, $crimeCap -= 10, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-	<br>//Costs <<print cashFormat(Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will bring down the crime level cap by 10 points, but will require 5 extra slaves in the headquarters and increases upkeep.//
+	[[Install auto-curating archiver|securityHQ][cashX(-Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $crimeUpgrades.autoArchive = 1, $SecExp.core.crimeCap -= 10, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
+	<br>//Costs <<print cashFormat(Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will bring down the crime level cap by 10 points, but will require 5 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 <<else>>
 	You have installed auto-curating archiver software, which will update in real time your data archives with any new relevant information on criminals residing in your arcology.
 <</if>>
 <br>
-<<if $authority > 10000>>
+<<if $SecExp.core.authority > 10000>>
 	<<if $crimeUpgrades.autoTrial == 0>>
-		[[Install automated trials software|securityHQ][cashX(-Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $crimeUpgrades.autoTrial = 1, $crimeCap -= 15, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-		<br>//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will bring down the crime level cap by 15 points, but will require 10 extra slaves in the headquarters and increases upkeep.//
+		[[Install automated trials software|securityHQ][cashX(-Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $crimeUpgrades.autoTrial = 1, $SecExp.core.crimeCap -= 15, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
+		<br>//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will bring down the crime level cap by 15 points, but will require 10 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 	<<else>>
 		You have installed advanced legal algorithms that allows the handling of legal matters much quicker and much more accurately.
 	<</if>>
 	<br>
 	<<if $crimeUpgrades.worldProfiler == 0>>
-		[[Install worldwide profilers|securityHQ][cashX(-Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $crimeUpgrades.worldProfiler = 1, $crimeCap -= 15, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-		<br>//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will bring down the crime level cap by 15 points, but will require 10 extra slaves in the headquarters and increases upkeep.//
+		[[Install worldwide profilers|securityHQ][cashX(-Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $crimeUpgrades.worldProfiler = 1, $SecExp.core.crimeCap -= 15, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
+		<br>//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will bring down the crime level cap by 15 points, but will require 10 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 	<<else>>
 		You have installed advanced profiler software, which will constantly scour every known data archive on the globe (legally or not) to gather as much information as possible on dangerous criminals.
 	<</if>>
@@ -326,22 +326,22 @@ Considering the current upgrades the maximum level of crime is <<print $crimeCap
 
 <<if $intelUpgrades.sensors == 0>>
 	[[Install perimeter sensors|securityHQ][cashX(-Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $intelUpgrades.sensors = 1, $recon += 1, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-	<br>//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will increase recon capabilities, but will require 5 extra slaves in the headquarters and increases upkeep.//
+	<br>//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will increase recon capabilities, but will require 5 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 <<else>>
 	You have installed perimeter seismic sensors able to detect movement with high accuracy.
 <</if>>
 <br>
 <<if $intelUpgrades.signalIntercept == 0>>
 	[[Create signal interception hub|securityHQ][cashX(-Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $intelUpgrades.signalIntercept = 1, $recon += 1, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-	<br>//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will increase recon capabilities, but will require 5 extra slaves in the headquarters and increases upkeep.//
+	<br>//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will increase recon capabilities, but will require 5 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 <<else>>
 	You have installed advanced signal interception equipment.
 <</if>>
 <br>
-<<if $authority > 10000>>
+<<if $SecExp.core.authority > 10000>>
 	<<if $intelUpgrades.radar == 0>>
 		[[Install advanced radar equipment|securityHQ][cashX(-Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $intelUpgrades.radar = 1, $recon += 1, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-		<br>//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will increase recon capabilities, but will require 10 extra slaves in the headquarters and increases upkeep.//
+		<br>//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will increase recon capabilities, but will require 10 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 	<<else>>
 		You have installed sophisticated radar equipment.
 	<</if>>
@@ -369,29 +369,29 @@ Considering the current upgrades the maximum level of crime is <<print $crimeCap
 
 <<if $readinessUpgrades.pathways == 0>>
 	[[Build specialized pathways in the arcology|securityHQ][cashX(-Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount), "capEx"), $readinessUpgrades.pathways = 1, $readiness += 1, $secHQUpkeep += $upgradeUpkeep]]
-	<br>//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will increase readiness by 1, but will increase upkeep.//
+	<br>//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will increase readiness by 1, but will increase upkeep. The remaining slaves will be more efficient in dealling with crime.//
 <<else>>
 	You have built specialized pathways inside the arcology to quickly move troops around the structure.
 <</if>>
 <br>
 <<if $readinessUpgrades.rapidVehicles == 0>>
 	[[Buy rapid armored transport vehicles|securityHQ][cashX(-Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount), "capEx"), $readinessUpgrades.rapidVehicles = 1, $readiness += 2, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep]]
-	<br>//Costs <<print cashFormat(Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will increase readiness by 2, but will require 5 extra slaves in the headquarters and increases upkeep.//
+	<br>//Costs <<print cashFormat(Math.trunc(7500*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will increase readiness by 2, but will require 5 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 <<else>>
 	You have bought rapid armored transport vehicles able to bring your troops to battle much quicker than before.
 <</if>>
 <br>
-<<if $authority > 10000>>
+<<if $SecExp.core.authority > 10000>>
 	<<if $readinessUpgrades.rapidPlatforms == 0>>
 		[[Build rapid deployment platforms|securityHQ][cashX(-Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount), "capEx"), $readinessUpgrades.rapidPlatforms = 1, $readiness += 2, $reqMenials += 5, $secHQUpkeep += $upgradeUpkeep]]
-		<br>//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will increase readiness by 2, but will require 5 extra slaves in the headquarters and increases upkeep.//
+		<br>//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will increase readiness by 2, but will require 5 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 	<<else>>
 		You have built rapid deployment platforms able to equip and deploy units within very limited time windows.
 	<</if>>
 	<br>
 	<<if $readinessUpgrades.earlyWarn == 0>>
 		[[Institute early warning systems|securityHQ][cashX(-Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount), "capEx"), $readinessUpgrades.earlyWarn = 1, $readiness += 2, $reqMenials += 10, $secHQUpkeep += $upgradeUpkeep]]
-		<br>//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will increase readiness by 2, but will require 10 extra slaves in the headquarters and increases upkeep.//
+		<br>//Costs <<print cashFormat(Math.trunc(15000*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will increase readiness by 2, but will require 10 extra slaves in the headquarters and increases upkeep. The remaining slaves will be more efficient in dealling with crime.//
 	<<else>>
 		You have created early warning systems that constantly analyze in real time data to determine the likeness of an attack.
 	<</if>>
@@ -402,46 +402,46 @@ Considering the current upgrades the maximum level of crime is <<print $crimeCap
 <br>
 <br>
 
-<<if $authority > 12000>>
+<<if $SecExp.core.authority > 12000>>
 	<br>__Cold Data Storage Facility__:
-	<<if $secUpgrades.coldstorage == 6 && $authority >= 19500 && $reqMenials > 10>>
+	<<if $reqMenials <= 10>>
+		<br>Personnel cannot be further reduced.
+	<<elseif $secUpgrades.coldstorage > 6>>
+		<br>You have installed a cold storage facility for the Security HQ's archives with a data retention capability of three years.
+	<<elseif $secUpgrades.coldstorage == 6 && $SecExp.core.authority >= 19500 && $reqMenials > 10>>
 		<br>You have installed a cold storage facility for the Security HQ's archives with a data retention capability of two years.
 		<br>
 		[[Expand the cold storage facility to increase data retention to three years|securityHQ][cashX(-Math.trunc(2400000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-		<br>//Costs <<print cashFormat(Math.trunc(2400000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep.//
-	<<elseif $secUpgrades.coldstorage == 5 && $authority >= 19500 && $reqMenials > 10>>
+		<br>//Costs <<print cashFormat(Math.trunc(2400000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep. The remaining slaves will be more efficient in dealling with crime.//
+	<<elseif $secUpgrades.coldstorage == 5 && $SecExp.core.authority >= 19500 && $reqMenials > 10>>
 	<br>You have installed a cold storage facility for the Security HQ's archives with a data retention capability of one year.
 		<br>
 		[[Expand the cold storage facility to increase data retention to two years|securityHQ][cashX(-Math.trunc(1200000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-		<br>//Costs <<print cashFormat(Math.trunc(1200000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep.//
-	<<elseif $secUpgrades.coldstorage == 4 && $authority >= 19500 && $reqMenials > 10>>
+		<br>//Costs <<print cashFormat(Math.trunc(1200000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep. The remaining slaves will be more efficient in dealling with crime.//
+	<<elseif $secUpgrades.coldstorage == 4 && $SecExp.core.authority >= 19500 && $reqMenials > 10>>
 		<br>You have installed a cold storage facility for the Security HQ's archives with a data retention capability of nine months.
 		<br>
 		[[Expand the cold storage facility to increase data retention to one year|securityHQ][cashX(-Math.trunc(900000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-		<br>//Costs <<print cashFormat(Math.trunc(900000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep.//
-	<<elseif $secUpgrades.coldstorage == 3 && $authority > 18000 && $reqMenials > 10>>
+		<br>//Costs <<print cashFormat(Math.trunc(900000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep. The remaining slaves will be more efficient in dealling with crime.//
+	<<elseif $secUpgrades.coldstorage == 3 && $SecExp.core.authority > 18000 && $reqMenials > 10>>
 		<br>You have installed a cold storage facility for the Security HQ's archives with a data retention capability of six months.
 		<br>
 		[[Expand the cold storage facility to increase data retention to nine months|securityHQ][cashX(-Math.trunc(600000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-		<br>//Costs <<print cashFormat(Math.trunc(600000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep.//
-	<<elseif $secUpgrades.coldstorage == 2 && $authority > 16000 && $reqMenials > 10>>
+		<br>//Costs <<print cashFormat(Math.trunc(600000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep. The remaining slaves will be more efficient in dealling with crime.//
+	<<elseif $secUpgrades.coldstorage == 2 && $SecExp.core.authority > 16000 && $reqMenials > 10>>
 		<br>You have installed a cold storage facility for the Security HQ's archives with a data retention capability of three months.
 		<br>
 		[[Expand the cold storage facility to increase data retention to six months|securityHQ][cashX(-Math.trunc(300000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-		<br>//Costs <<print cashFormat(Math.trunc(300000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep.//
-	<<elseif $secUpgrades.coldstorage == 1 && $authority > 14000 && $reqMenials > 10>>
+		<br>//Costs <<print cashFormat(Math.trunc(300000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep. The remaining slaves will be more efficient in dealling with crime.//
+	<<elseif $secUpgrades.coldstorage == 1 && $SecExp.core.authority > 14000 && $reqMenials > 10>>
 		<br>You have installed a cold storage facility for the Security HQ's archives with a data retention capability of one month.
 		<br>
 		[[Expand the cold storage facility to increase data retention to three months|securityHQ][cashX(-Math.trunc(100000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-		<br>//Costs <<print cashFormat(Math.trunc(100000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep.//
-	<<elseif $secUpgrades.coldstorage == 0 && $authority > 12000 && $reqMenials > 10>>
+		<br>//Costs <<print cashFormat(Math.trunc(100000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by a further 10, but will increase upkeep. The remaining slaves will be more efficient in dealling with crime.//
+	<<elseif $secUpgrades.coldstorage == 0 && $SecExp.core.authority > 12000 && $reqMenials > 10>>
 		[[Install a cold storage facility|securityHQ][cashX(-Math.trunc(50000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier), "capEx"), $secUpgrades.coldstorage++, $reqMenials -= 10, $secHQUpkeep += $upgradeUpkeep, $PC.hacking += 1]]
-		<br>//Costs <<print cashFormat(Math.trunc(50000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by 10, but will increase upkeep.//
-	<<elseif $secUpgrades.coldstorage > 6>>
-		<br>You have installed a cold storage facility for the Security HQ's archives with a data retention capability of three years.
-	<<elseif $reqMenials <= 10>>
-		<br>Personnel cannot be further reduced.
-	<<else>>
-		<br>You lack the authority to access more advanced upgrades.
+		<br>//Costs <<print cashFormat(Math.trunc(50000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier))>>. Will lower the amount of required slaves by 10, but will increase upkeep. The remaining slaves will be more efficient in dealling with crime.//
 	<</if>>
-<</if>>
+<<else>>
+	<br>You lack the authority to access more advanced upgrades.
+<</if>>
\ No newline at end of file
diff --git a/src/SecExp/securityReport.tw b/src/SecExp/securityReport.tw
index 3e12668d6fe..b4b48cef980 100644
--- a/src/SecExp/securityReport.tw
+++ b/src/SecExp/securityReport.tw
@@ -123,30 +123,30 @@
 		<<set _secGrowth -= 2>>
 	<</if>>
 <</if>>
-<<if $crime < 20>>
+<<if $SecExp.core.crimeLow < 20>>
 	Crime is a distant problem in the arcology, which makes improving security easier.
 	<<set _secGrowth += 1>>
-<<elseif $crime < 40>>
+<<elseif $SecExp.core.crimeLow < 40>>
 	Crime is a minor problem in the arcology, not serious enough to disrupt security efforts.
-<<elseif $crime < 60>>
+<<elseif $SecExp.core.crimeLow < 60>>
 	Crime is an issue in the arcology, which makes improving security harder.
 	<<set _secGrowth -= 0.5>>
-<<elseif $crime < 80>>
+<<elseif $SecExp.core.crimeLow < 80>>
 	Crime is an overbearing problem in the arcology, which makes improving security a lot harder.
 	<<set _secGrowth -= 1>>
 <<else>>
 	Crime is sovereign in the arcology, which makes improving security extremely difficult.
 	<<set _secGrowth -= 2>>
 <</if>>
-<<if $authority < 5000>>
+<<if $SecExp.core.authority < 5000>>
 	The low authority you hold on the arcology hampers the efforts of your security department.
 	<<set _secGrowth -= 1>>
-<<elseif $authority < 7500>>
+<<elseif $SecExp.core.authority < 7500>>
 	The limited authority you hold on the arcology hampers the efforts of your security department.
 	<<set _secGrowth -= 0.5>>
-<<elseif $authority < 10000>>
+<<elseif $SecExp.core.authority < 10000>>
 	The authority you hold on the arcology does not significantly impact the efforts of your security department.
-<<elseif $authority < 15000>>
+<<elseif $SecExp.core.authority < 15000>>
 	The high authority you hold on the arcology facilitates the security department's work.
 	<<set _secGrowth += 0.5>>
 <<else>>
@@ -208,24 +208,24 @@
 <</if>>
 
 /* resting point */
-<<set _secRest = $secRestPoint * (Math.clamp($secMenials,0,$reqMenials) / $reqMenials)>>
+<<set _secRest = $SecExp.security.low * (Math.clamp($secMenials,0,$reqMenials) / $reqMenials)>>
 <<if _secRest < 0>>
 	<<set _secRest = 20>>
 <</if>>
-<<if _secRest < $secRestPoint && $secHQ == 1>>
+<<if _secRest < $SecExp.security.low && $secHQ == 1>>
 	The limited staff assigned to the HQ hampered the improvements to security achieved this week.
-<<elseif _secRest < $secRestPoint>>
+<<elseif _secRest < $SecExp.security.low>>
 	The limited infrastructure available slowly erodes away the security level of the arcology.
 <</if>>
 
 The security level of the arcology is
-<<if $security > (_secRest + 5)>>
+<<if $SecExp.security.cap > (_secRest + 5)>>
 	over its effective resting point, limiting the achievable growth this week.
 	<<set _secGrowth *= 0.5>>
-<<elseif $security < (_secRest - 5)>>
+<<elseif $SecExp.security.cap < (_secRest - 5)>>
 	under its effective resting point, speeding up its growth.
 	<<set _secGrowth *= 1.5>>
-<<elseif $security == _secRest>>
+<<elseif $SecExp.security.cap == _secRest>>
 	at its effective resting point, this severely limits the influence of external factors on the change achievable this week.
 	<<set _secGrowth *= 0.3>>
 <<else>>
@@ -234,16 +234,16 @@ The security level of the arcology is
 		<<set _secGrowth *= 0.3>>
 	<</if>>
 <</if>>
-<<set _restGrowth = (_secRest - $security) * 0.2>>
-<<set _newSec = Math.trunc($security + _secGrowth + _restGrowth)>>
-<<if _newSec < $security>>
+<<set _restGrowth = (_secRest - $SecExp.security.cap) * 0.2>>
+<<set _newSec = Math.trunc($SecExp.security.cap + _secGrowth + _restGrowth)>>
+<<if _newSec < $SecExp.security.cap>>
 	This week @@.red;security decreased.@@
-<<elseif _newSec == $security>>
+<<elseif _newSec == $SecExp.security.cap>>
 	This week @@.yellow;security did not change.@@
 <<else>>
 	This week @@.green;security improved.@@
 <</if>>
-<<set $security = Math.clamp(_newSec, 0, 100)>>
+<<set $SecExp.security.cap = Math.clamp(_newSec, 0, 100)>>
 
 <br><br>
 <strong>Crime</strong>:
@@ -298,27 +298,27 @@ Due to the deterioration of the old world countries, organized crime focuses mor
 	The number of slaves in the arcology is becoming a big issue for law enforcement, facilitating crime growth.
 	<<set _crimeGrowth += 1.5>>
 <</if>>
-<<if $security <= 20>>
+<<if $SecExp.security.cap <= 20>>
 	The security measures in place are severely limited, allowing crime to grow uncontested.
-<<elseif $security <= 50>>
+<<elseif $SecExp.security.cap <= 50>>
 	The security measures in place are of limited effect and use, giving only mixed results in their fight against crime.
 	<<set _crimeGrowth -= 1.5>>
-<<elseif $security <= 75>>
+<<elseif $SecExp.security.cap <= 75>>
 	The security measures in place are well developed and effective, making a serious dent in the profitability of criminal activity in your arcology.
 	<<set _crimeGrowth -= 3>>
 <<else>>
 	The security measures in place are extremely well developed and very effective, posing a serious threat even to the most powerful criminal organizations in existence.
 	<<set _crimeGrowth -= 5.5>>
 <</if>>
-<<if $authority < 5000>>
+<<if $SecExp.core.authority < 5000>>
 	Your low authority allows crime to grow undisturbed.
 	<<set _crimeGrowth += 1>>
-<<elseif $authority < 7500>>
+<<elseif $SecExp.core.authority < 7500>>
 	Your relatively low authority facilitates criminal activities.
 	<<set _crimeGrowth += 0.5>>
-<<elseif $authority < 10000>>
+<<elseif $SecExp.core.authority < 10000>>
 	Your authority is not high enough to discourage criminal activity.
-<<elseif $authority < 15000>>
+<<elseif $SecExp.core.authority < 15000>>
 	Your high authority is an effective tool against crime.
 	<<set _crimeGrowth -= 1>>
 <<else>>
@@ -334,19 +334,26 @@ Due to the deterioration of the old world countries, organized crime focuses mor
 <</if>>
 
 /* crime cap */
-<<set _crimeCap = Math.trunc(Math.clamp($crimeCap + ($crimeCap - $crimeCap * ($secMenials / $reqMenials)),0,100))>>
-<<if _crimeCap > $crimeCap && $secHQ == 1>>
+<<set _crimeCap = Math.trunc(Math.clamp($SecExp.core.crimeCap + ($SecExp.core.crimeCap - $SecExp.core.crimeCap * ($secMenials / $reqMenials)),0,100))>>
+<<if _crimeCap > $SecExp.core.crimeCap && $secHQ == 1>>
 	The limited staff assigned to the HQ allows more space for criminals to act.
 <</if>>
-<<set _newCrime = Math.trunc(Math.clamp($crime + _crimeGrowth,0,_crimeCap))>>
-<<if _newCrime > $crime>>
+<<if $SecExp.core.authority > 12000>>
+	<<if $secUpgrades.coldstorage < 6>>
+		<<if $secUpgrades.coldstorage === 0>>Adding a facility<<else>>Improving the cold storage facility attached<</if>> to the SecurityHQ should allow the staff to be more efficient in dealling with crime.
+	<<else>>
+		The cold storage facility attached to SecurityHQ allows the staff to be more efficient in dealling with crime.
+	<</if>>
+<</if>>
+<<set _newCrime = Math.trunc(Math.clamp($SecExp.core.crimeLow + _crimeGrowth,0,_crimeCap))>>
+<<if _newCrime > $SecExp.core.crimeLow>>
 	This week @@.red;crime increased.@@
-<<elseif _newCrime == $crime>>
+<<elseif _newCrime == $SecExp.core.crimeLow>>
 	This week @@.yellow;crime did not change.@@
 <<else>>
 	This week @@.green;crime decreased.@@
 <</if>>
-<<set $crime = Math.clamp(_newCrime,0,100)>>
+<<set $SecExp.core.crimeLow = Math.clamp(_newCrime,0,100)>>
 
 <<if $militiaFounded == 1 || $activeUnits >= 1>>
 	<br><br>
@@ -379,7 +386,7 @@ Due to the deterioration of the old world countries, organized crime focuses mor
 			Many citizens volunteer just to fight for someone of your renown.
 			<<set _recruitLimit += 0.0025>>
 		<</if>>
-		<<if $authority >= 10000>>
+		<<if $SecExp.core.authority >= 10000>>
 			Many citizens feel it is their duty to fight for you, boosting volunteer enrollment.
 			<<set _recruitLimit += 0.0025>>
 		<</if>>
@@ -495,7 +502,7 @@ Due to the deterioration of the old world countries, organized crime focuses mor
 			The very high prosperity of the arcology attracts a lot of mercenaries, hopeful to find lucrative contracts within its walls.
 			<<set _newMercs += random(3,5)>>
 		<</if>>
-		<<if $crime > 60>>
+		<<if $SecExp.core.crimeLow > 60>>
 			The powerful crime organizations that nested themselves in the arcology have an unending need for cheap guns for hire, many mercenaries flock to your free city in search of employment.
 			<<set _newMercs += random(1,2)>>
 		<</if>>
@@ -747,4 +754,4 @@ Due to the deterioration of the old world countries, organized crime focuses mor
 		It will be finished in <<if $currentUpgrade.time == 1>> one week.<<else>><<print $currentUpgrade.time>> weeks.<</if>>
 	<</if>>
 <</if>>
-<br>
+<br>
\ No newline at end of file
diff --git a/src/SecExp/widgets/miscSecExpWidgets.tw b/src/SecExp/widgets/miscSecExpWidgets.tw
index e58a019b374..87c4031c99a 100644
--- a/src/SecExp/widgets/miscSecExpWidgets.tw
+++ b/src/SecExp/widgets/miscSecExpWidgets.tw
@@ -72,7 +72,7 @@
 		<<set _newRest += 20>>
 	<</if>>
 	<<set _newRest += _baseRest>>
-	<<set $secRestPoint = _newRest>>
+	<<set $SecExp.security.low = _newRest>>
 <</widget>>
 
 <<widget "recalcCrimeCap">>
@@ -90,7 +90,7 @@
 	<<if $crimeUpgrades.advForensic == 1>>
 		<<set _newCap -= 15>>
 	<</if>>
-	<<set $crimeCap = _newCap>>
+	<<set $SecExp.core.crimeCap = _newCap>>
 <</widget>>
 
 <<widget "recalcReqMenials">>
diff --git a/src/SpecialForce/SpecialForce.js b/src/SpecialForce/SpecialForce.js
index 05d525747f6..757476e40ed 100644
--- a/src/SpecialForce/SpecialForce.js
+++ b/src/SpecialForce/SpecialForce.js
@@ -2314,9 +2314,9 @@ App.SF.AAR = function(endWeekCall = 1) {
 			Multiplier.troop += S.Troops / 200;
 			upkeep += (S.Troops * 25) / cost.a;
 			if (V.secExp > 0 && endWeekCall > 0) {
-				V.authority += 25 * (Math.ceil(S.Troops / 200));
-				V.authority += V.SF.Size * 10;
-				V.authority = Math.clamp(V.authority, 0, 20000);
+				V.SecExp.core.authority += 25 * (Math.ceil(S.Troops / 200));
+				V.SecExp.core.authority += V.SF.Size * 10;
+				V.SecExp.core.authority = Math.clamp(V.SecExp.core.authority, 0, 20000);
 			}
 		}
 
diff --git a/src/uncategorized/BackwardsCompatibility.tw b/src/uncategorized/BackwardsCompatibility.tw
index 96e3153d892..47dd22b0d0c 100644
--- a/src/uncategorized/BackwardsCompatibility.tw
+++ b/src/uncategorized/BackwardsCompatibility.tw
@@ -3687,7 +3687,7 @@ Done<br>
 	<br>
 	<<include "SecExpBackwardCompatibility">>
 <<else>>
-	<<set $crime = 0, $security = 0>>
+	<<set $SecExp.core.crimeLow = 0, $SecExp.security.cap = 0>>
 <</if>>
 
 <<if ndef $masteredXP>>
diff --git a/src/uncategorized/arcmgmt.tw b/src/uncategorized/arcmgmt.tw
index aa8cf82b111..1a8ac923788 100644
--- a/src/uncategorized/arcmgmt.tw
+++ b/src/uncategorized/arcmgmt.tw
@@ -743,7 +743,7 @@ $menialBioreactors -= _expirationBR>>
 	<<set _transportHub = 1>>
 <</if>>
 <<if $secExp == 1>>
-	<<set _crime = (100 - $crime) / 100 + 0.2>>
+	<<set _crime = (100 - $SecExp.core.crimeLow) / 100 + 0.2>>
 <<else>>
 	<<set _crime = 0.8>>
 <</if>>
@@ -1431,14 +1431,14 @@ You own
 		<<set _AWeekGrowth++>>
 	<</if>>
 	<<if $secExp == 1>>
-		<<if $authority > 18000>>
+		<<if $SecExp.core.authority > 18000>>
 			Your authority is so high it discourages new business, slowing down the economic growth of the arcology.
 			<<set _AWeekGrowth-->>
 		<</if>>
-		<<if $security > 80>>
+		<<if $SecExp.security.cap > 80>>
 			Your arcology is extremely safe and stable. Many businesses are attracted to it because of this.
 			<<set _AWeekGrowth++>>
-		<<elseif $security < 20>>
+		<<elseif $SecExp.security.cap < 20>>
 			Your arcology's low security is an instability factor simply too dangerous to be ignored. Many businesses avoid your arcology because of this.
 			<<set _AWeekGrowth-->>
 		<</if>>
diff --git a/src/uncategorized/main.tw b/src/uncategorized/main.tw
index 189226f8c0e..6a0d134e53a 100644
--- a/src/uncategorized/main.tw
+++ b/src/uncategorized/main.tw
@@ -1,7 +1,10 @@
 :: Main [nobr]
 
 <<if $releaseID >= 1000 || ["0.9", "0.8", "0.7", "0.6"].includes($ver)>>
-	<<if $releaseID >= 1047>>
+	<<if $releaseID >= 1049>>
+	<<elseif $releaseID < 1049 && ndef $SecExp>>
+		<<= App.SecExp.Check.general()>>
+		<<goto "Main">>
 	<<elseif $releaseID < 1047 && ndef $sideBarOptions>>
 		''@@.red;INCOMPATIBILITY WARNING:@@'' your saved game was created using version $ver build $releaseID. Due to major changes to the side bar, you must run [[backwards compatibility|Backwards Compatibility]].
 	<<elseif $releaseID < 1046>>
@@ -200,4 +203,4 @@ __''MAIN MENU''__&nbsp;&nbsp;&nbsp;&nbsp;//[[Summary Options]]//
 <</if>>
 <<if ($debugMode == 1)>>
 	//| [[Show all walk past scenes|Walk Past List]]//
-<</if>>
+<</if>>
\ No newline at end of file
diff --git a/src/uncategorized/neighborsDevelopment.tw b/src/uncategorized/neighborsDevelopment.tw
index f89fc69162d..5252c4a2ac0 100644
--- a/src/uncategorized/neighborsDevelopment.tw
+++ b/src/uncategorized/neighborsDevelopment.tw
@@ -558,7 +558,7 @@ has an estimated GSP of @@.yellowgreen;<<print cashFormat(_prosperity)>><<if $sh
 		<<set $arcologies[0].prosperity -= $arcologies[0].CyberEconomic*3, _redHanded = 1>>
 		<<run repX(forceNeg(random(100,200)), "war")>>
 		<<if $secExp == 1>>
-			<<set $authority -= random(100,500)*$arcologies[0].CyberEconomic, $crime += random(10,25)>>
+			<<set $SecExp.core.authority -= random(100,500)*$arcologies[0].CyberEconomic, $SecExp.core.crimeLow += random(10,25)>>
 		<</if>>
 		<<set $arcologies[0].prosperity = Math.clamp($arcologies[0].prosperity, 1, $AProsperityCap)>>
 	<</if>>
@@ -600,7 +600,7 @@ has an estimated GSP of @@.yellowgreen;<<print cashFormat(_prosperity)>><<if $sh
 		<<set $arcologies[0].prosperity -= $arcologies[0].CyberReputation*3, _redHanded = 1>>
 		<<run repX(forceNeg(random(100,200)), "war")>>
 		<<if $secExp == 1>>
-			<<set $authority -= random(100,500)*$arcologies[0].CyberReputation, $crime += random(10,25)>>
+			<<set $SecExp.core.authority -= random(100,500)*$arcologies[0].CyberReputation, $SecExp.core.crimeLow += random(10,25)>>
 		<</if>>
 		<<set $arcologies[0].prosperity = Math.clamp($arcologies[0].prosperity, 1, 300)>>
 	<</if>>
diff --git a/src/uncategorized/options.tw b/src/uncategorized/options.tw
index 90714a769a2..3b34e107829 100644
--- a/src/uncategorized/options.tw
+++ b/src/uncategorized/options.tw
@@ -791,10 +791,10 @@ This save was created using FC version $ver build $releaseID.
 			<tr style="text-align:center">
 			<td colspan="2">
 			<<link "Give Authority" "Options">>
-				<<set $authority = Math.clamp($authority + 1000, 0, 20000)>>
+				<<set $SecExp.core.authority = Math.clamp($SecExp.core.authority + 1000, 0, 20000)>>
 			<</link>>
 			| <<link "Remove Authority" "Options">>
-				<<set $authority = Math.clamp($authority - 1000, 0, 20000)>>
+				<<set $SecExp.core.authority = Math.clamp($SecExp.core.authority - 1000, 0, 20000)>>
 			<</link>>
 			</td>
 			</tr>
@@ -802,19 +802,19 @@ This save was created using FC version $ver build $releaseID.
 			<tr>
 			<td style="text-align:right">
 			<<link "Raise security" "Options">>
-				<<set $security = Math.clamp($security + 5, 0, 100)>>
+				<<set $SecExp.security.cap = Math.clamp($SecExp.security.cap + 5, 0, 100)>>
 			<</link>>
 			| <<link "Lower security" "Options">>
-				<<set $security = Math.clamp($security - 5, 0, 100)>>
+				<<set $SecExp.security.cap = Math.clamp($SecExp.security.cap - 5, 0, 100)>>
 			<</link>>
 			</td>
 
 			<td style="text-align:left">
 			<<link "Raise crime" "Options">>
-				<<set $crime = Math.clamp($crime + 5, 0, 100)>>
+				<<set $SecExp.core.crimeLow = Math.clamp($SecExp.core.crimeLow + 5, 0, 100)>>
 			<</link>>
 			| <<link "Lower crime" "Options">>
-				<<set $crime = Math.clamp($crime - 5, 0, 100)>>
+				<<set $SecExp.core.crimeLow = Math.clamp($SecExp.core.crimeLow - 5, 0, 100)>>
 			<</link>>
 			</td>
 			</tr>
diff --git a/src/uncategorized/persBusiness.tw b/src/uncategorized/persBusiness.tw
index 32db170feff..64f64751aad 100644
--- a/src/uncategorized/persBusiness.tw
+++ b/src/uncategorized/persBusiness.tw
@@ -374,9 +374,9 @@
 	After several days of preparation you are ready to issue the proclamation. You announce to the arcology your plans and in short order you use <<if $proclamationCurrency == "authority">>control over the arcology<<elseif $proclamationCurrency == "reputation">>great influence<<elseif $proclamationCurrency == "cash">> vast financial means<</if>> to
 	<<if $proclamationType == "security">>
 		gather crucial information for your security department. In just a few many hours holes are plugged and most moles are eliminated. @@.green;Your security greatly increased.@@
-		<<set $security = Math.clamp($security + 25,0,100)>>
+		<<set $SecExp.security.cap = Math.clamp($SecExp.security.cap + 25,0,100)>>
 		<<if $proclamationCurrency == "authority">>
-			<<set $authority = Math.clamp($authority - 2000,0,20000)>>
+			<<set $SecExp.core.authority = Math.clamp($SecExp.core.authority - 2000,0,20000)>>
 		<<elseif $proclamationCurrency == "reputation">>
 			<<run repX((Math.clamp($rep - 2000,0,20000)) - $rep, "personalBusiness")>>
 		<<else>>
@@ -384,9 +384,9 @@
 		<</if>>
 	<<elseif $proclamationType == "crime">>
 		force the arrest of many suspected citizens. Their personal power allowed them to avoid justice for a long time, but this day is their end. @@.green;Your crime greatly decreased.@@
-		<<set $crime = Math.clamp($crime - 25,0,100)>>
+		<<set $SecExp.core.crimeLow = Math.clamp($SecExp.core.crimeLow - 25,0,100)>>
 		<<if $proclamationCurrency == "authority">>
-			<<set $authority = Math.clamp($authority - 2000,0,20000)>>
+			<<set $SecExp.core.authority = Math.clamp($SecExp.core.authority - 2000,0,20000)>>
 		<<elseif $proclamationCurrency == "reputation">>
 			<<run repX(Math.clamp($rep - 2000,0,20000), "personalBusiness")>>
 		<<else>>
@@ -637,7 +637,7 @@
 	<<if random(0,100) >= _Catchtchance>>
 		However, since the source of the attack was traced back to your arcology, your
 		<<if $secExp == 1>> <<set _X = 1>>
-			@@.red;authority,@@ <<set $authority -= random(100,500)>> @@.red;crime rate@@ <<set $crime += random(10,25)>> and
+			@@.red;authority,@@ <<set $SecExp.core.authority -= random(100,500)>> @@.red;crime rate@@ <<set $SecExp.core.crimeLow += random(10,25)>> and
 		<</if>>
 		@@.red;reputation@@ <<run repX(forceNeg(random(50,500)), "event")>>
 		<<if _X != 1>>
@@ -743,14 +743,14 @@
 			You are selling the data collected by your security department, which earns a discreet sum of @@.yellowgreen;<<print cashFormat(_dataGain)>>.@@
 			<<run cashX(_dataGain, "personalBusiness")>>
 			Many of your citizens are not enthusiastic of this however, @@.red;damaging your authority.@@
-			<<set $authority -= 50>>
+			<<set $SecExp.core.authority -= 50>>
 		<</if>>
 	<</if>>
 
 	<<if $marketInfiltration == 1>>
 		<<set _blackMarket = random(7000,8000)>>
 		Your secret service makes use of black markets and illegal streams of goods to make a profit, making you @@.yellowgreen;<<print cashFormat(_blackMarket)>>.@@ This however allows @@.red;crime to flourish@@ in the underbelly of the arcology.
-		<<set $crime += random(1,3)>>
+		<<set $SecExp.core.crimeLow += random(1,3)>>
 	<</if>>
 
 	<<if $arcRepairTime > 0>>
diff --git a/src/uncategorized/storyCaption.tw b/src/uncategorized/storyCaption.tw
index fff342fa754..a1c057f5c12 100644
--- a/src/uncategorized/storyCaption.tw
+++ b/src/uncategorized/storyCaption.tw
@@ -380,95 +380,95 @@
 		<<if $secExp == 1 && ( $sideBarOptions.Authority > 0 || $sideBarOptions.Security > 0 || $sideBarOptions.Crime > 0)>>
 			<<if $sideBarOptions.Authority > 0>> <br>
 				@@.darkviolet;Auth@@ |
-				<<set $authority = Math.clamp(Math.trunc($authority), 0, 20000)>>
+				<<set $SecExp.core.authority = Math.clamp(Math.trunc($SecExp.core.authority), 0, 20000)>>
 				<span id="auth">
-				<<if $authority > 19500>>
+				<<if $SecExp.core.authority > 19500>>
 					@@color:rgb(148, 0, 211);divine will@@
-				<<elseif $authority > 19000>>
+				<<elseif $SecExp.core.authority > 19000>>
 					@@color:rgb(148, 0, 211);sovereign@@
-				<<elseif $authority > 18000>>
+				<<elseif $SecExp.core.authority > 18000>>
 					@@color:rgb(148, 0, 211);monarch@@
-				<<elseif $authority > 17000>>
+				<<elseif $SecExp.core.authority > 17000>>
 					@@color:rgb(148, 0, 211);tyrant@@
-				<<elseif $authority > 15000>>
+				<<elseif $SecExp.core.authority > 15000>>
 					@@color:rgb(148, 0, 211);dictator@@
-				<<elseif $authority > 14000>>
+				<<elseif $SecExp.core.authority > 14000>>
 					@@color:rgb(148, 0, 211);prince@@
-				<<elseif $authority > 13000>>
+				<<elseif $SecExp.core.authority > 13000>>
 					@@color:rgb(183, 0, 211);master@@
-				<<elseif $authority > 12000>>
+				<<elseif $SecExp.core.authority > 12000>>
 					@@color:rgb(183, 0, 211);leader@@
-				<<elseif $authority > 11000>>
+				<<elseif $SecExp.core.authority > 11000>>
 					@@color:rgb(183, 0, 211);director@@
-				<<elseif $authority > 10000>>
+				<<elseif $SecExp.core.authority > 10000>>
 					@@color:rgb(183, 0, 211);overseer@@
-				<<elseif $authority > 9000>>
+				<<elseif $SecExp.core.authority > 9000>>
 					@@color:rgb(183, 0, 211);chief@@
-				<<elseif $authority > 8000>>
+				<<elseif $SecExp.core.authority > 8000>>
 					@@color:rgb(183, 0, 211);manager@@
-				<<elseif $authority > 7000>>
+				<<elseif $SecExp.core.authority > 7000>>
 					@@color:rgb(211,0,204);principal@@
-				<<elseif $authority > 6000>>
+				<<elseif $SecExp.core.authority > 6000>>
 					@@color:rgb(211,0,204);auxiliary@@
-				<<elseif $authority > 5000>>
+				<<elseif $SecExp.core.authority > 5000>>
 					@@color:rgb(211,0,204);subordinate@@
-				<<elseif $authority > 4000>>
+				<<elseif $SecExp.core.authority > 4000>>
 					@@color:rgb(211,0,204);follower@@
-				<<elseif $authority > 3000>>
+				<<elseif $SecExp.core.authority > 3000>>
 					@@color:rgb(211,0,204);powerless@@
-				<<elseif $authority > 2000>>
+				<<elseif $SecExp.core.authority > 2000>>
 					@@color:rgb(211,0,204);toothless@@
-				<<elseif $authority > 1000>>
+				<<elseif $SecExp.core.authority > 1000>>
 					@@color:rgb(211,0,204);mostly harmless@@
 				<<else>>
 					@@color:rgb(211,0,204);harmless@@
 				<</if>>
-				(<<print num($authority)>>)
+				(<<print num($SecExp.core.authority)>>)
 				</span>
 				<<if (_Pass == "Main")>>
 					<<if ($cheatMode) && ($cheatModeM)>>
-						<<set _TAuth = $authority>>
-						<<textbox "$authority" $authority>>
+						<<set _TAuth = $SecExp.core.authority>>
+						<<textbox "$SecExp.core.authority" $SecExp.core.authority>>
 						<<link "Apply">>
-							<<set $authority = Math.clamp(Math.trunc(Number($authority) || _TAuth), 0, 20000), $cheater = 1>>
+							<<set $SecExp.core.authority = Math.clamp(Math.trunc(Number($SecExp.core.authority) || _TAuth), 0, 20000), $cheater = 1>>
 							<<replace "#auth">>
-								<<if $authority > 19500>>
+								<<if $SecExp.core.authority > 19500>>
 									@@color:rgb(148, 0, 211);divine will@@
-								<<elseif $authority > 19000>>
+								<<elseif $SecExp.core.authority > 19000>>
 									@@color:rgb(148, 0, 211);sovereign@@
-								<<elseif $authority > 18000>>
+								<<elseif $SecExp.core.authority > 18000>>
 									@@color:rgb(148, 0, 211);monarch@@
-								<<elseif $authority > 17000>>
+								<<elseif $SecExp.core.authority > 17000>>
 									@@color:rgb(148, 0, 211);tyrant@@
-								<<elseif $authority > 15000>>
+								<<elseif $SecExp.core.authority > 15000>>
 									@@color:rgb(148, 0, 211);dictator@@
-								<<elseif $authority > 14000>>
+								<<elseif $SecExp.core.authority > 14000>>
 									@@color:rgb(148, 0, 211);prince@@
-								<<elseif $authority > 13000>>
+								<<elseif $SecExp.core.authority > 13000>>
 									@@color:rgb(183, 0, 211);master@@
-								<<elseif $authority > 12000>>
+								<<elseif $SecExp.core.authority > 12000>>
 									@@color:rgb(183, 0, 211);leader@@
-								<<elseif $authority > 11000>>
+								<<elseif $SecExp.core.authority > 11000>>
 									@@color:rgb(183, 0, 211);director@@
-								<<elseif $authority > 10000>>
+								<<elseif $SecExp.core.authority > 10000>>
 									@@color:rgb(183, 0, 211);overseer@@
-								<<elseif $authority > 9000>>
+								<<elseif $SecExp.core.authority > 9000>>
 									@@color:rgb(183, 0, 211);chief@@
-								<<elseif $authority > 8000>>
+								<<elseif $SecExp.core.authority > 8000>>
 									@@color:rgb(183, 0, 211);manager@@
-								<<elseif $authority > 7000>>
+								<<elseif $SecExp.core.authority > 7000>>
 									@@color:rgb(211,0,204);principal@@
-								<<elseif $authority > 6000>>
+								<<elseif $SecExp.core.authority > 6000>>
 									@@color:rgb(211,0,204);auxiliary@@
-								<<elseif $authority > 5000>>
+								<<elseif $SecExp.core.authority > 5000>>
 									@@color:rgb(211,0,204);subordinate@@
-								<<elseif $authority > 4000>>
+								<<elseif $SecExp.core.authority > 4000>>
 									@@color:rgb(211,0,204);follower@@
-								<<elseif $authority > 3000>>
+								<<elseif $SecExp.core.authority > 3000>>
 									@@color:rgb(211,0,204);powerless@@
-								<<elseif $authority > 2000>>
+								<<elseif $SecExp.core.authority > 2000>>
 									@@color:rgb(211,0,204);toothless@@
-								<<elseif $authority > 1000>>
+								<<elseif $SecExp.core.authority > 1000>>
 									@@color:rgb(211,0,204);mostly harmless@@
 								<<else>>
 									@@color:rgb(211,0,204);harmless@@
@@ -481,16 +481,16 @@
 
 			<<if $sideBarOptions.Security > 0>>
 				<span id="sec"> <br>
-					@@.deepskyblue;Security@@ | @@.deepskyblue;<<print Math.trunc($security)>>%@@
+					@@.deepskyblue;Security@@ | @@.deepskyblue;<<print Math.trunc($SecExp.security.cap)>>%@@
 				</span>
 				<<if (_Pass == "Main")>>
 					<<if ($cheatMode) && ($cheatModeM)>>
-						<<set _TSec = $security>>
-						<<textbox "$security" $security>>
+						<<set _TSec = $SecExp.security.cap>>
+						<<textbox "$SecExp.security.cap" $SecExp.security.cap>>
 						<<link "Apply">>
-						<<set $security = Math.clamp(Math.trunc(Number($security) || _TSec), 0, 100), $cheater = 1>>
+						<<set $SecExp.security.cap = Math.clamp(Math.trunc(Number($SecExp.security.cap) || _TSec), 0, 100), $cheater = 1>>
 						<<replace "#sec">>
-						<br>@@.deepskyblue;Security@@ | <<print Math.trunc($security)>>%
+						<br>@@.deepskyblue;Security@@ | <<print Math.trunc($SecExp.security.cap)>>%
 						<</replace>>
 						<</link>>
 					<</if>>
@@ -499,16 +499,16 @@
 
 			<<if $sideBarOptions.Crime > 0>>
 				<span id="crime"> <br>
-					@@.orangered;Crime@@ | @@.orangered;<<print Math.trunc($crime)>>%@@
+					@@.orangered;Crime@@ | @@.orangered;<<print Math.trunc($SecExp.core.crimeLow)>>%@@
 				</span>
 				<<if (_Pass == "Main")>>
 					<<if ($cheatMode) && ($cheatModeM)>>
-						<<set _TCrime = $crime>>
-						<<textbox "$crime" $crime>>
+						<<set _TCrime = $SecExp.core.crimeLow>>
+						<<textbox "$SecExp.core.crimeLow" $SecExp.core.crimeLow>>
 						<<link "Apply">>
-						<<set $crime = Math.clamp(Math.trunc(Number($crime) || _TCrime), 0, 100), $cheater = 1>>
+						<<set $SecExp.core.crimeLow = Math.clamp(Math.trunc(Number($SecExp.core.crimeLow) || _TCrime), 0, 100), $cheater = 1>>
 						<<replace "#crime">>
-						<br>@@.orangered;Crime@@ | <<print Math.trunc($crime)>>%
+						<br>@@.orangered;Crime@@ | <<print Math.trunc($SecExp.core.crimeLow)>>%
 						<</replace>>
 						<</link>>
 					<</if>>
-- 
GitLab