How to save the current orientation of the camera when it is moved?

hey all, the title might not be clear, but my problem is when this camera panning script pans left, the script puts it back to the default setting, I know why this happens, and is the first part of the code from lines 12 to 15. my question is, how do i influence that code to go with my bottom code?

local RunService = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local cam = game.Workspace.CurrentCamera

cam.CameraType = "Scriptable"

local camCF = workspace.gamer.CFrame
local angle = 0

RunService.RenderStepped:Connect(function()
	local center = Vector2.new(cam.ViewportSize.X / 2, cam.ViewportSize.Y / 2)
	local rotVector = Vector3.new((mouse.X - center.X) / 150, (mouse.Y - center.Y) / 150, 0)
	
	cam.CFrame = camCF * CFrame.Angles(math.atan(math.rad(-rotVector.Y)), math.atan(math.rad(-rotVector.X)), rotVector.Z)

	if mouse.X < 250 and angle > -180 then
		print("panning left")
		angle = angle - 3
		
		cam.CFrame = cam.CFrame * CFrame.Angles(0, math.tanh(-math.rad(cam.CFrame.Y + angle)), 0)
		wait(0.1)
	elseif mouse.X > 1750 and angle < 180 then
		print("panning right")
		angle = angle + 3
		
		cam.CFrame = cam.CFrame * CFrame.Angles(0, math.tanh(math.rad(cam.CFrame.Y - angle)), 0)
		wait(0.1)
	end
end)