function Maid.DoCleaning(t)local a=t._tasks for t,R in pairs(a)do if typeof(R)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then a[t]=nil R:Disconnect()end end local R,P=next(a)while P~=nil do a[R]=nil if type(P)=="\102\117\110\099\116\105\111\110"then P()elseif type(P)=="\116\104\114\101\097\100"then task.cancel(P)elseif typeof(P)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then P:Disconnect()elseif P.Destroy then P:Destroy()end R,P=next(a)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 type(job) == "thread" then
			task.cancel(job)
		elseif typeof(job) == "RBXScriptConnection" then
			job:Disconnect()
		elseif job.Destroy then
			job:Destroy()
		end
		index, job = next(tasks)
	end
end
