Help with CharacterController rotating down?

Hi I’m making a simple top-down 8-axis movement CharacterController that rotates in the Direction of movement. When the character is moving it works perfectly fine however when not moving the controller just rotates to be facing down towards the ground attached is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

    [SerializeField]
    private Transform rotatableTransform = null;

    public float speed = 6.0f;
    public float gravity = 20.0f;

    private Vector3 moveDirection = Vector3.zero;

    CharacterController controller;

    // Start is called before the first frame update
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {

        if (controller.isGrounded)
        {
            moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0.0f, Input.GetAxisRaw("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection = moveDirection.normalized;
            moveDirection *= speed;
        }
        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);

        rotatableTransform.rotation = Quaternion.Slerp(rotatableTransform.rotation, Quaternion.LookRotation(moveDirection), 0.15f);
    }
}

This is what it does upon entering play mode:

In case anyone happens upon this and has the same issue the fix was just moving the rotation calculation before all the movement calculations. Also placing it within an if statement to check the moveDirection wasn’t zero.

void Update()
    {

        moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0.0f, Input.GetAxisRaw("Vertical"));

        if(moveDirection != Vector3.zero)
        {
            rotatableTransform.rotation = Quaternion.Slerp(rotatableTransform.rotation, Quaternion.LookRotation(moveDirection), 0.15f);
        }

        moveDirection = transform.TransformDirection(moveDirection);
        moveDirection = moveDirection.normalized;
        moveDirection *= speed;

        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);
    }