Prevent Movement and Rotation after stopping diagonal movement

I currently have the problem, that if I move diagonally, and then completely stop moving, it still takes that last millisecond of input of one of the 2 directions I am pressing (eg. S and D), and rotates and moves towards it. which I don’t want, and feels bad.

What can I do to prevent that?

Movement script:

using UnityEngine;

[RequireComponent(typeof(CharacterController))]
public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 5.335f; // Default sprint speed
    public float rotationSmoothTime = 0.12f;
    public float speedChangeRate = 10.0f;
    
    private float _currentSpeed;
    private float _targetRotation;
    private float _rotationVelocity;
    private float _verticalVelocity;
    private Vector3 _moveDirection;
    private float _gravity = -9.81f;

    private CharacterController _characterController;
    private PlayerInputs _playerInput;
    private GameObject _mainCamera;

    private Animator _animator;

    private void Start()
    {
        _characterController = GetComponent<CharacterController>();
        _playerInput = GetComponent<PlayerInputs>();
        _mainCamera = Camera.main.gameObject;
        _animator = GetComponent<Animator>();
    }

    private void Update()
    {
        Move();
        ApplyGravity();
        UpdateAnimator();
    }

    private void Move()
    {
        // Normalize input direction
        _moveDirection = new Vector3(_playerInput.move.x, 0f, _playerInput.move.y).normalized;

        if (_moveDirection != Vector3.zero)
        {
            _targetRotation = Mathf.Atan2(_moveDirection.x, _moveDirection.z) * Mathf.Rad2Deg + _mainCamera.transform.eulerAngles.y;
            float rotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, _targetRotation, ref _rotationVelocity, rotationSmoothTime);
            transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f);
        }

        // Always use moveSpeed
        float targetSpeed = _moveDirection == Vector3.zero ? 0f : moveSpeed;

        // Accelerate or decelerate to target speed
        float currentHorizontalSpeed = new Vector3(_characterController.velocity.x, 0.0f, _characterController.velocity.z).magnitude;
        if (Mathf.Abs(currentHorizontalSpeed - targetSpeed) > 0.1f)
        {
            _currentSpeed = Mathf.Lerp(currentHorizontalSpeed, targetSpeed, Time.deltaTime * speedChangeRate);
            _currentSpeed = Mathf.Round(_currentSpeed * 1000f) / 1000f;
        }
        else
        {
            _currentSpeed = targetSpeed;
        }

        Vector3 moveDirection = Quaternion.Euler(0.0f, _targetRotation, 0.0f) * Vector3.forward;
        _characterController.Move(moveDirection.normalized * (_currentSpeed * Time.deltaTime) + new Vector3(0.0f, _verticalVelocity, 0.0f) * Time.deltaTime);
    }

    private void ApplyGravity()
    {
        if (_characterController.isGrounded)
        {
            _verticalVelocity = -2f; // Small downward force to keep grounded
        }
        else
        {
            _verticalVelocity += _gravity * Time.deltaTime; // Apply gravity when not grounded
        }
    }

    private void UpdateAnimator()
    {
        if (_animator)
        {
            _animator.SetFloat("Speed", _currentSpeed);
        }
    }
}

Does it work if you set in your else part _currentSpeed = targetSpeed; to _currentSpeed = 0; ?