Enemy wander behaviour and chasing player, need it to reset.

Hey guys,
So ive got a basic wandering script and what it does is if the player gets too close, the enemy chases the player for a certain distance and then runs back, But the problem is when the player runs too far and the enemy tries to run back he get stuck because he needs to run back bu the player is still within chasing distance so it gets confused.
Any help would be appreciated.

The script:

using UnityEngine;
using System.Collections;

public class EnemyAI : MonoBehaviour 
{
	public float enemySpeed = 5.0f;
	public Transform myTarget;
	public GameObject go;
	private Vector3 startPosition;
	private bool isWandering = true;
	public bool inCombat = false;
	public float enemyWanderSpeed = 3.0f;
	public float wanderRange = 10.0f;
	public float wanderDelayTimer;
	public float distanceToCombat = 8.0f;
	public float distanceToDropCombat = 40.0f;
	public bool chasingPlayer = false;
	public NavMeshAgent agent;


	void Awake()
	{
		go = GameObject.FindGameObjectWithTag("Player");
		agent = GetComponent<NavMeshAgent>();
		agent.speed  = enemyWanderSpeed;
		startPosition = this.transform.position;
	}
	void Update () 
	{
		Debug.Log(transform.position);

		startWander();
		float distanceFromPlayer = Vector3.Distance(transform.position, go.transform.position);
		float distanceChasedCombat = Vector3.Distance(transform.position, startPosition);

		if(distanceFromPlayer <= distanceToCombat)
		{
			chasingPlayer = true;
		}
		//if it chased the player too far run back and start wandering around, by setting the wander delay timer to 0 so it runs back straight away.
		if(distanceChasedCombat >= distanceToDropCombat)
		{
			chasingPlayer = false;
			wanderDelayTimer = 0.0f;
		}
		if(chasingPlayer)
		{
			myTarget = go.transform;
			agent.SetDestination(myTarget.transform.position);
			agent.speed = enemySpeed;
		}

	}
	void startWander()
	{

		wanderDelayTimer -=Time.deltaTime;
		if(wanderDelayTimer <= 0 && !chasingPlayer)
		{
			Wander();
			wanderDelayTimer = 5.0f;
		}
	}
	void Wander()
	{
		agent.speed = enemyWanderSpeed;
		Vector3 destination = startPosition + new Vector3 (Random.Range (-wanderRange, wanderRange),0 /*transform.position.y*/, Random.Range(-wanderRange, wanderRange));
		newDestination(destination);
	}
	public void newDestination(Vector3 targetPoint)
	{
		agent.SetDestination (targetPoint);
	}
}

So the enemy does not run back because it is still within the range that triggers the chase? Sounds like maybe you need another boolean to check if the enemy is returning and only set chasingPlayer = true if it is false? So something like:

if(distanceFromPlayer <= distanceToCombat && !isReturning)
{
   chasingPlayer = true;
}

And then set isReturning = false once the enemy is back at its starting position.