diff --git a/sim/simulation.lua b/sim/simulation.lua
index f8631bb..5744153 100644
--- a/sim/simulation.lua
+++ b/sim/simulation.lua
@@ -267,16 +267,14 @@ end
 
 -- Logic Critical
 function Simulation.queuegroup(sim, group)
-	--if group.in_queue==0 then
-		sim.groupqueue[sim.num_groupqueue+1] = group
-		sim.num_groupqueue = sim.num_groupqueue + 1
-		group.in_queue = 1
-	--end
+	sim.groupqueue[sim.num_groupqueue+1] = group
+	sim.num_groupqueue = sim.num_groupqueue + 1
+	group.in_queue = 1
 end
 
 function Simulation.dequeuegroup(sim, group)
 	if group.in_queue~=0 then
-		array_remove(sim.groupqueue, group)
+		array_remove(sim.groupqueue, group, true)
 		sim.num_groupqueue = sim.num_groupqueue - 1
 		group.in_queue = 0
 	end
@@ -285,7 +283,7 @@ end
 
 function Simulation.dequeuegate(sim, gate)
 	if gate.in_queue~=0 then
-		array_remove(sim.gatequeue, gate)
+		array_remove(sim.gatequeue, gate, true)
 		sim.num_gatequeue = sim.num_gatequeue - 1
 		gate.in_queue = 0
 	end
@@ -307,13 +305,12 @@ end
 
 -- Logic Critical
 function Simulation.ticklogic(sim)
-	local len = sim.num_groupqueue
-	for i = 1, len do
+	for i = 1, sim.num_groupqueue do
 		local group = sim.groupqueue[i]
 		Group.update(group)
 		group.in_queue = 0
 	end
-	sim.groupqueue = {}
+	--sim.groupqueue = {}
 	sim.num_groupqueue = 0
 	
 	if sim.tickqueue[sim.current_tick] ~= nil then
@@ -323,13 +320,12 @@ function Simulation.ticklogic(sim)
 		sim.tickqueue[sim.current_tick] = nil
 	end
 	
-	local len = sim.num_gatequeue
-	for i = 1, len do
+	for i = 1, sim.num_gatequeue do
 		local gate = sim.gatequeue[i]
 		gate.logic(gate)
 		gate.in_queue = 0
 	end
-	sim.gatequeue = {}
+	--sim.gatequeue = {}
 	sim.num_gatequeue = 0
 	
 	sim.current_tick = sim.current_tick + 1
diff --git a/sim/utility.lua b/sim/utility.lua
index e8df85d..33962fa 100644
--- a/sim/utility.lua
+++ b/sim/utility.lua
@@ -68,7 +68,7 @@ function tobitstring(num, len)
 	return bitstring
 end
 
-function array_remove(array, value)
+function array_remove(array, value, pass)
 	for i = 1, #array do
 		local v = array[i]
 		if v==value then
@@ -77,7 +77,7 @@ function array_remove(array, value)
 			return
 		end
 	end
-	error("element not in array")
+	if not pass then error("element not in array") end
 end
 
 function array_add(array, value)