Cursor not locking in center of screen?

So I wrote a movement script that includes a cursor lock and hide function. The problem is, is that when I unlock the cursor with the Escape key, the cursor can freely move around. That is what I wanted it to do. When I re-lock the cursor, it disappears ONLY when it is on the game screen, but it can still freely move around. When it exits the game frame, it shows. It does not lock on re-lock. How would I fix this?

private bool isMouseLocked = true;

void Update () {

		if (Input.GetButtonDown ("Unlock")) {
			isMouseLocked = !isMouseLocked; 

		if (isMouseLocked == true) {
			Cursor.lockState = CursorLockMode.Locked; 
			Cursor.visible = false; 

		if (isMouseLocked == false) {
			Cursor.lockState = CursorLockMode.None; 
			Cursor.visible = true; 

I’m making some assumptions here, but I’m pretty sure that Unity’s acknowledgement of where the cursor is becomes “locked” but it doesn’t actually lock where Windows registers the cursor as being.

A solution would be to look through .NET to see if you can find some cursor control functionality to import. I’m near certain I’ve seen something along those lines before.