diff --git a/game/engines/default/engine/GameEnergyBased.lua b/game/engines/default/engine/GameEnergyBased.lua
index 9e49bcbaa506a98f2f71c558bbdb655fe7c4871f..bfdb984053c0ec550fe3bc43a10e9a386da32e24 100644
--- a/game/engines/default/engine/GameEnergyBased.lua
+++ b/game/engines/default/engine/GameEnergyBased.lua
@@ -72,9 +72,9 @@ function _M:tick()
 		self.level = mainlev
 	end
 
-	local arr = self.entities
+	local arr = table.clone(self.entities)
 	for i, e in pairs(arr) do
-		e = arr[i]
+		e = self.entities[i]
 		if e and e.act and e.energy then
 			if e.energy.value < self.energy_to_act then
 				e.energy.value = (e.energy.value or 0) + self.energy_per_tick * (e.energy.mod or 1) * (e.global_speed or 1)
@@ -97,19 +97,19 @@ function _M:tickLevel(level)
 	local arr = level.e_array
 
 	if level.last_iteration then
-		i = nil
-
-		for ii = 1, #arr do if arr[ii] == level.last_iteration.e then i = ii + 1 break end end
-
-		if not i then i = level.last_iteration.i + 1 end
+		i = level.last_iteration.i + 1
 
 		if i > #arr then i = 1 end
 		level.last_iteration = nil
 --		print("=====LEVEL", level.level, level.sublevel_id, "resuming tick loop at ", i, arr[i].name)
 	end
 
-	for i = i, #arr do
+	level.last_iteration = {}  -- mark as iterating
+	local iter = level.last_iteration
+	local finished = true
+	while i <= #arr do
 		e = arr[i]
+		iter.e, iter.i = e, i
 		if e and e.act and e.energy then
 			if e.actBase and e.energyBase then
 				if e.energyBase < self.energy_to_act then
@@ -131,12 +131,14 @@ function _M:tickLevel(level)
 --			print(">ENERGY", e.name, e.uid, "::", e.energy.value, self.paused, "::", e.player)
 
 			if self.can_pause and self.paused then
-				level.last_iteration = {i=i, e=e}
+				finished = false
 --				print("====LEVEL", level.level, level.sublevel_id, "pausing tick loop at ", i, e.name)
 				break
 			end
 		end
+		i = iter.i + 1
 	end
+	if finished then level.last_iteration = nil end
 end
 
 --- Called every game turns
diff --git a/game/engines/default/engine/Level.lua b/game/engines/default/engine/Level.lua
index c74c47fe74e2c60d36d4e41eeda33cd696ff52e7..959b67b6d325aae2167ebbdb274527cfa207387e 100644
--- a/game/engines/default/engine/Level.lua
+++ b/game/engines/default/engine/Level.lua
@@ -107,6 +107,9 @@ function _M:addEntity(e, after, no_error)
 		end
 		if pos then
 			table.insert(self.e_array, pos+1, e)
+			if self.last_iteration and self.last_iteration.i >= pos then
+				self.last_iteration.i = self.last_iteration.i + 1
+			end
 		else
 			table.insert(self.e_array, e)
 		end
@@ -126,12 +129,19 @@ function _M:removeEntity(e, force)
 
 	if not self.entities[e.uid] and not force then error("Entity "..e.uid.."("..(e.name or "???")..") not present on the level") end
 	self.entities[e.uid] = nil
+	local pos = nil
 	for i = 1, #self.e_array do
 		if self.e_array[i] == e then
-			table.remove(self.e_array, i)
+			pos = i
 			break
 		end
 	end
+	if pos then
+		if self.last_iteration and self.last_iteration.i >= pos then
+			self.last_iteration.i = self.last_iteration.i - 1
+		end
+		table.remove(self.e_array, pos)
+	end
 	game:removeEntity(e)
 
 	-- Tells it to delete itself if needed