function Maid.DoCleaning(p)local J=p._tasks for p,v in pairs(J)do if typeof(v)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then J[p]=nil v:Disconnect()end end local v,A=next(J)while A~=nil do J[v]=nil if type(A)=="\102\117\110\099\116\105\111\110"then A()elseif typeof(A)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then A:Disconnect()elseif A.Destroy then A:Destroy()end v,A=next(J)end end

function Maid:DoCleaning()
	local tasks = self._tasks

	-- Disconnect all events first as we know this is safe
	for index, job in pairs(tasks) do
		if typeof(job) == "RBXScriptConnection" then
			tasks[index] = nil
			job:Disconnect()
		end
	end

	-- Clear out tasks table completely, even if clean up tasks add more tasks to the maid
	local index, job = next(tasks)
	while job ~= nil do
		tasks[index] = nil
		if type(job) == "function" then
			job()
		elseif typeof(job) == "RBXScriptConnection" then
			job:Disconnect()
		elseif job.Destroy then
			job:Destroy()
		end
		index, job = next(tasks)
	end
end
