Camera Follow Code Causes Jerky Movements

I need a script that will act like the included SmoothFollow.js but will also rotate on the X and Z axes. I messed around with it and came up with this:

var target : Transform;

var distance = 5.0;

function Update () {

    if (!target) {
        return;
    }
        
    wantedRotationAngleY = target.eulerAngles.y;
    currentRotationAngleY = transform.eulerAngles.y;

    wantedRotationAngleX = target.eulerAngles.x;
    currentRotationAngleX = transform.eulerAngles.x;


    currentRotationAngleY = Mathf.LerpAngle(currentRotationAngleY, wantedRotationAngleY, Time.deltaTime);    
    currentRotationAngleX = Mathf.LerpAngle(currentRotationAngleX, wantedRotationAngleX, Time.deltaTime);

    
    currentRotation = Quaternion.Euler(currentRotationAngleX, currentRotationAngleY, 0);


    transform.position = target.position;
    transform.position -= currentRotation * Vector3.forward * distance;

	transform.localEulerAngles = target.transform.localEulerAngles;

}

The script shown above does its intended job perfectly however it is extremely jerky when
rotating especially on X axis rotation. Is there a way to better write this script or a way to smooth it? Once this is fixed I will be applying dampening so making the camera a child is not an option. Thank you.

To anyone looking for a script like this, MrProffesorTroll has fixed it. Please read the comments under the question for an explanation but here is the completed code without dampening added:

var target : Transform;

var distance = 5.0;

function FixedUpdate () {

    if (!target) {
        return;
    }
        
    wantedRotationAngleY = target.eulerAngles.y;
    currentRotationAngleY = transform.eulerAngles.y;
    
    wantedRotationAngleX = target.eulerAngles.x;
    currentRotationAngleX = transform.eulerAngles.x;


    currentRotationAngleY = Mathf.LerpAngle(currentRotationAngleY, wantedRotationAngleY, Time.deltaTime);    
    currentRotationAngleX = Mathf.LerpAngle(currentRotationAngleX, wantedRotationAngleX, Time.deltaTime);

    
    currentRotation = Quaternion.Euler(currentRotationAngleX, currentRotationAngleY, 0);


	transform.localEulerAngles = target.transform.localEulerAngles;

    transform.position = target.position;
    transform.position -= currentRotation * Vector3.forward * distance;

}

I don’t know if anyone has noticed this but if you get jerky movements with the follow transform script from the mobile assets, i found a way to stop it jerking but its not a fix, i was fiddling around trying to find out what made the character so jerky and found that is was the follow transform script on the camera pivot, though if you run the game and turn the script off and on again in the inspector while the game is still running, it thens runs perfectly smooth like in previous versions of unity, if this helps anyone with fixing the script that would be great.