Same Tables function

Feedback on the code please, anything you think I missed?

local G = require(game:GetService("ReplicatedStorage"):WaitForChild("Global"))

return function(t1, t2)
	if #t1 ~= #t2 then
		return
	end

	local a1 = {}
	local a2 = {}

	local function sort(a, t1, t2)
		table.sort(t1)
		table.sort(t2)

		local i = 0
		for key, value in t1 do
			i += 1

			if typeof(t2[key]) == "table" or typeof(value) == "table" then
				if
					typeof(t2[key]) == "table"
					and typeof(value) == "table"
					and G.SameTables(t2[key], value)
				then
					a[i] = {key, G.HttpService:JSONEncode(value)}
				else
					return
				end
			else
				if t2[key] == value then
					a[i] = {key, value}
				else
					return
				end
			end
		end

		return true
	end

	if sort(a1, t1, t2) and sort(a2, t2, t1) then
		return G.HttpService:JSONEncode(a1) == G.HttpService:JSONEncode(a2)
	end
end