Saving Rotation of Sprite

Hello programmers who are better than me! I have this code, which is working beautifully at facing my sprite in whichever direction it is moving. The problem is that when it stops moving the sprite locks back to its initial rotation, when I would like it to stay at the rotation it was at just before stopping. How can I achieve this? Many thanks.

using UnityEngine;
using System.Collections;

public class FaceDirection : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {


		Vector2 moveDirection = gameObject.GetComponent<Rigidbody2D>().velocity;

			float angle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg;
			transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

	}
	

}

Try checking if the magnitude of moveDirection is above a small threshold before changing the rotation:

    Vector2 moveDirection = gameObject.GetComponent<Rigidbody2D>().velocity;
    if (moveDirection.magnitude > .01f) {
         float angle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg;
         transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
    }