How do I undo mouselock

Alright so I have a script to lock the players mouse in the middle of the screen, However Im unsure of how to undo it, Im able to undo it and the mouse moves freely however the camera is all glitched, I cant rotate it at all. Its all in a local script

Make players mouse lock:

RunService:BindToRenderStep("MouseLock",Enum.RenderPriority.Last.Value+1,function()
						UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
					end)

Undo the mouselock:

RunService:BindToRenderStep("MouseLock",Enum.RenderPriority.Last.Value+1,function()
								UIS.MouseBehavior = Enum.MouseBehavior.Default
							end)
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")

local KeyCode = Enum.KeyCode.E

function MouseLock(Name)
	RS:BindToRenderStep(Name, Enum.RenderPriority.Input.Value - 1, function()
		UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
	end)
	return function() RS:UnbindFromRenderStep(Name) UIS.MouseBehavior = Enum.MouseBehavior.Default end
end

UIS.InputBegan:Connect(function(Key, gameProcessed)
	if Key.KeyCode == KeyCode and not gameProcessed then
		local unbind = MouseLock("MouseLock")
		
		repeat RS.Heartbeat:Wait()
		until not UIS:IsKeyDown(KeyCode)
		
		unbind()
	end
end)