Walk animation doesn't stop immediately.

I have want my player to start the walk animation when I press the “a” or “d” keys and I want it to stop playing the animation when I release them. The animation plays when I press on of the keys but after I release them the animation plays further to the end before stopping! How can I fix this?
Thx for your help! Here is my code:

using UnityEngine;
using System.Collections;

public class PlayerHorizontal : MonoBehaviour {
	public float MoveSpeed;
	public bool IsWalking;
	public Animator anim;

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

		//set IsWalking
		if(Input.GetKey("a")) {
			IsWalking = true;	
			transform.eulerAngles = new Vector2(0 ,180);
			transform.Translate(Vector2.right * 4f * Time.deltaTime);
		} 

		if (Input.GetKey("d")) {
			IsWalking = true;
			transform.eulerAngles = new Vector2(0, 0);
			transform.Translate(Vector2.right * 4f * Time.deltaTime);
		}


		if (Input.GetKeyUp ("a")) {
						IsWalking = false;	

				} else if ((Input.GetKeyUp ("d"))) {
			IsWalking = false;
		}

		



		anim.SetBool ("IsWalking", IsWalking);	
	}


}

try toggling your Atomic value on the transition in Mecanim to make the state/transition interruptible. Read more in docs: http://docs.unity3d.com/Manual/class-Transition.html

Uncheck the “Atomic” checkbox in your transition between ‘walking’ and ‘idle/not moving’. Also, make sure that your conditions for the transition do not include the default “Exit Time”, but your own condition such as a bool which indicates that you released the keys.

To get to the above menu, click on the arrow between the 2 states.