Movement acceleration

Hello, I’m trying to make a movement engine that goes like this:
On W press, start with a slow speed then gradually go up as long as you keep holding W.
After W is no longer pressed, quickly deaccelerate and then stop.

This is a part of my script. What’s wrong with it?

void Update()
{
            if(isgrounded)
            {
                movedirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
                movedirection = transform.TransformDirection(movedirection);
                speed = Mathf.Lerp(initialspeed, newspeed, timespeed * Time.deltaTime);
    
                if (Input.GetKey(KeyCode.W))
                {
                    newspeed = 30;
                }
                if (Input.GetKeyUp(KeyCode.W))
                {
                    newspeed = 5;
                }
                movedirection *= speed;
}

Or is therea another way instead of using mathf.lerp for accelerating?