Issue with TraceHull override

Hi. I’m trying to make an override for TraceHull so that I can add an entity to the filter. The following code works for overriding TraceLine:
[lua]
if !util.RealTraceLine then – If the function is broken or disabled, use the usual one
util.RealTraceLine = util.TraceLine
end
function util.TraceLine(tr) – Override for TraceLine
if !MapRepeat then – If MapRepeat is not active, use normal TraceLine
util.TraceLine = util.RealTraceLine
return util.TraceLine(tr)
end

cell,tr.start,tr.endpos = MapRepeat.PosToCell(tr.start,tr.endpos) -- Gets cell and position data.
for _,e in pairs(ents.GetAll()) do 
	if !MapRepeat.InCell(e,cell) && (CLIENT or e:GetMoveType() != MOVETYPE_NONE) then -- If the entity is not in the cell
		if type(tr.filter) != 'table' then tr.filter = {tr.filter} end -- If the table isn't valid, make it a table
		tr.filter[#tr.filter+1] = e -- Add the entity to the filter
	end
end

local tro = util.RealTraceLine(tr) -- Make a new traceline using the old data
tro.HitPos = MapRepeat.CellToPos(tro.HitPos,cell) -- Find the relative position in the cell and override HitPos
tro.StartPos = tr.start -- Set StartPos to the trace's start
return tro -- Return new traceline

[/lua]

However, when I tried to do something similar for TraceHull (notice the commented-out lines and debug prints):

[lua]
if !util.RealTraceHull then
util.RealTraceHull = util.TraceHull
end
function util.TraceHull(th)
if !MapRepeat then
util.TraceHull = util.RealTraceHull
return util.TraceHull(th)
end

cell,th.start,th.endpos = MapRepeat.PosToCell(th.start,th.endpos)
for _,e in pairs(ents.GetAll()) do
	if e:IsVehicle() or !MapRepeat.InCell(e,cell) && (CLIENT or e:GetMoveType() != MOVETYPE_NONE) then
		if type(th.filter) != 'table' then th.filter = {th.filter} end
		th.filter[#th.filter+1] = e
		//print("Hitting: "..tostring(th.Entity))
	end
end

local tho = util.RealTraceHull(th)
//tho.Entity = th.Entity
//tho.HitPos = MapRepeat.CellToPos(tho.HitPos,cell)
//tho.StartPos = th.start
tho.filter = th.filter
PrintTable({tho.filter})
print(tostring(tho.Hit).." | "..tostring(tho.Entity))
return tho

end
[/lua]

It doesn’t work. In a vehicle (vehicle thirdperson uses TraceHull), the camera stays at my head. The prints give me:
[lua]
1:
1 = function: 0x18ad6ae0
2 = Entity [39][func_brush]
3 = Entity [40][func_brush]
4 = Entity [43][func_brush]
5 = Entity [44][func_brush]
6 = Entity [45][func_brush]
7 = Entity [46][func_brush]
8 = Entity [47][func_brush]
9 = Entity [54][func_brush]
10 = Entity [55][func_brush]
11 = Entity [56][func_brush]
12 = Entity [57][func_brush]
13 = Vehicle [59][prop_vehicle_jeep_old]
true | Vehicle [59][prop_vehicle_jeep_old]
[/lua]

Which doesn’t seem to make sense. If I uncomment the
[lua]tho.Entity = th.Entity[/lua]
it still hits, but says that the entity is a nil.

What am I doing wrong?

[editline]March 16[/editline]
I’ve tried Googling the issue, but I can’t seem to find anything helpful, and my coder friends can’t figure it out.

SOLVED! For anyone who might run into this problem, I did this:
[lua]
if !util.RealTraceHull then
util.RealTraceHull = util.TraceHull
end
function util.TraceHull(th)
if !MapRepeat then
util.TraceHull = util.RealTraceHull
return util.TraceHull(th)
end

cell,th.start,th.endpos = MapRepeat.PosToCell(th.start,th.endpos)

local tho = util.RealTraceHull( {
start = th.start,
endpos = th.endpos,
filter = function(e)
	if(type(th.filter) == 'function') then
		pass = th.filter(e)
	else
		pass = table.HasValue(th.filter,e)
	end
	return MapRepeat.InCell(e,cell) && pass
end,
mins = th.mins,
maxs = th.maxs,
} )

return tho

end
[/lua]

I just replaced the filter with a function (it also checks if the old tracehull was a function and adds to that)