Weapon sway issue

hello everyone, so im having a issue with my weapon sway. So when you move your mouse left to right, the gun sways smoothly but when move your mouse up and down, it is very buggy.

My code:

local function newmw(x,y,z)
	if not z then
		x,z,y = x.x, x.z, x.y
	end
	local m=z*z
	if m>1e-5 then
		return CFrame.new(math.sin(y),0,0) * CFrame.Angles(math.sin(x), math.sin(y), 0)  --the math.sin(y) is left and right. math.sin(x) is up and down. 
	else
		return CFrame.new()
	end
end

Video of proof (sorry for the lag):