diff --git a/src/mpgame/bots/Bot.cpp b/src/mpgame/bots/Bot.cpp
index ccfa946..118f219 100644
--- a/src/mpgame/bots/Bot.cpp
+++ b/src/mpgame/bots/Bot.cpp
@@ -233,7 +233,7 @@ void rvmBot::BotMoveToGoalOrigin(idVec3 goalOrigin)
 	idAngles desiredAngles = bs.botinput.dir.ToAngles();
 	if( bs.enemy >= 0 )
 	{
-		idPlayer* enemy = gameLocal.entities[bs.enemy]->Cast<idPlayer>();
+		idPlayer* enemy = BotPlayerForIndex( bs.enemy );
 		if( enemy )
 		{
 			desiredAngles = (enemy->firstPersonViewOrigin - firstPersonViewOrigin).ToAngles();
diff --git a/src/mpgame/bots/Bot.h b/src/mpgame/bots/Bot.h
index 7b53117..de7d279 100644
--- a/src/mpgame/bots/Bot.h
+++ b/src/mpgame/bots/Bot.h
@@ -829,6 +829,9 @@ struct bot_state_t
 
 #define Bot_Time() ((float)gameLocal.time / 1000.0f)
 
+idEntity* BotEntityForIndex( int entityNum );
+idPlayer* BotPlayerForIndex( int entityNum );
+
 //
 // rvmBot
 //
diff --git a/src/mpgame/bots/BotAI.cpp b/src/mpgame/bots/BotAI.cpp
index 11f70bc..34125fc 100644
--- a/src/mpgame/bots/BotAI.cpp
+++ b/src/mpgame/bots/BotAI.cpp
@@ -4,6 +4,18 @@
 
 
 #include "../Game_local.h"
+
+idEntity* BotEntityForIndex( int entityNum ) {
+	if ( entityNum < 0 || entityNum >= MAX_GENTITIES ) {
+		return NULL;
+	}
+	return gameLocal.entities[entityNum];
+}
+
+idPlayer* BotPlayerForIndex( int entityNum ) {
+	idEntity* entity = BotEntityForIndex( entityNum );
+	return entity ? entity->Cast<idPlayer>() : NULL;
+}
 #include "../ai/AASCallback_FindCoverArea.h"
 
 #define IDEAL_ATTACKDIST			140
@@ -193,6 +205,9 @@ rvmBot::EntityIsDead
 */
 bool rvmBot::EntityIsDead( idEntity* entity )
 {
+	if ( entity == NULL ) {
+		return true;
+	}
 	{
 		idPlayer* player = entity->Cast<idPlayer>();
 		if( player && player->health <= 0 )
@@ -222,8 +237,11 @@ float rvmBot::BotEntityVisibleTest( int viewer, idVec3 eye, idAngles viewangles,
 
 	//calculate middle of bounding box
 	//BotEntityInfo(ent, &entinfo);
-	entinfo = gameLocal.entities[ent];
-	viewEnt = gameLocal.entities[viewer]->Cast<idPlayer>();
+	entinfo = BotEntityForIndex( ent );
+	viewEnt = BotPlayerForIndex( viewer );
+	if ( entinfo == NULL || viewEnt == NULL ) {
+		return 0.0f;
+	}
 
 	//VectorAdd(entinfo->r.mins, entinfo->r.maxs, middle);
 	//VectorScale(middle, 0.5, middle);
@@ -382,7 +400,10 @@ void rvmBot::BotUpdateBattleInventory( bot_state_t* bs, int enemy )
 	idVec3 dir;
 	idEntity* entinfo;
 
-	entinfo = gameLocal.entities[enemy];
+	entinfo = BotEntityForIndex( enemy );
+	if ( entinfo == NULL ) {
+		return;
+	}
 
 	VectorSubtract( entinfo->GetOrigin(), bs->origin, dir );
 	bs->inventory[ENEMY_HEIGHT] = ( int )dir[2];
@@ -537,7 +558,10 @@ int rvmBot::BotFindEnemy( bot_state_t* bs, int curenemy )
 	alertness = botCharacterStatsManager.Characteristic_BFloat( bs->character, CHARACTERISTIC_ALERTNESS, 0, 1 );
 	easyfragger = botCharacterStatsManager.Characteristic_BFloat( bs->character, CHARACTERISTIC_EASY_FRAGGER, 0, 1 );
 
-	clientEnt = gameLocal.entities[bs->client]->Cast<idPlayer>();
+	clientEnt = BotPlayerForIndex( bs->client );
+	if ( clientEnt == NULL ) {
+		return false;
+	}
 
 	//check if the health decreased
 	healthdecrease = bs->lasthealth > bs->inventory[INVENTORY_HEALTH];
@@ -548,10 +572,10 @@ int rvmBot::BotFindEnemy( bot_state_t* bs, int curenemy )
 	if( curenemy >= 0 )
 	{
 		//BotEntityInfo(curenemy, &curenemyinfo);
-		curenemyinfo = gameLocal.entities[curenemy]->Cast<idPlayer>();
+		curenemyinfo = BotPlayerForIndex( curenemy );
 		if( curenemyinfo == NULL || EntityIsDead( curenemyinfo ) )
 		{
-			curenemy = -1;
+			bs->enemy = curenemy = -1;
 			cursquaredist = 0;
 		}
 		else
@@ -583,7 +607,7 @@ int rvmBot::BotFindEnemy( bot_state_t* bs, int curenemy )
 			continue;
 		}
 
-		entinfo = gameLocal.entities[i]->Cast<idPlayer>();
+		entinfo = BotPlayerForIndex( i );
 		if( !entinfo )
 		{
 			continue;
@@ -747,11 +771,15 @@ void rvmBot::BotAimAtEnemy( bot_state_t* bs )
 		return;
 	}
 
-	self = gameLocal.entities[bs->entitynum]->Cast<idPlayer>();
+	self = BotPlayerForIndex( bs->entitynum );
 
 	//get the enemy entity information
 	//BotEntityInfo(bs->enemy, &entinfo);
-	entinfo = gameLocal.entities[bs->enemy]->Cast<idPlayer>();
+	entinfo = BotPlayerForIndex( bs->enemy );
+	if ( self == NULL || entinfo == NULL ) {
+		bs->enemy = -1;
+		return;
+	}
 
 	//if this is not a player (should be an obelisk)
 	if( bs->enemy >= MAX_CLIENTS )
@@ -839,7 +867,11 @@ void rvmBot::BotAimAtEnemy( bot_state_t* bs )
 	}
 	//get the enemy entity information
 	//BotEntityInfo(bs->enemy, &entinfo);
-	entinfo = gameLocal.entities[bs->enemy]->Cast<idPlayer>();
+	entinfo = BotPlayerForIndex( bs->enemy );
+	if ( entinfo == NULL ) {
+		bs->enemy = -1;
+		return;
+	}
 
 	//if the enemy is invisible then shoot crappy most of the time
 	//if (entinfo->IsInvisible()) {
@@ -1226,7 +1258,11 @@ rvmBot::BotMoveInRandomDirection
 */
 int rvmBot::BotMoveInRandomDirection( bot_state_t* bs )
 {
-	rvmBot* ent = gameLocal.entities[bs->client]->Cast<rvmBot>();
+	idEntity* entity = BotEntityForIndex( bs->client );
+	rvmBot* ent = entity ? entity->Cast<rvmBot>() : NULL;
+	if ( ent == NULL ) {
+		return false;
+	}
 
 	//ent->ResetPathFinding();
 
@@ -1305,9 +1341,13 @@ void rvmBot::BotCheckAttack( bot_state_t* bs )
 	attackentity = bs->enemy;
 	//
 	//BotEntityInfo(attackentity, &entinfo);
-	entinfo = gameLocal.entities[attackentity];
+	entinfo = BotEntityForIndex( attackentity );
 
-	self = gameLocal.entities[bs->client]->Cast<idPlayer>();
+	self = BotPlayerForIndex( bs->client );
+	if ( entinfo == NULL || self == NULL ) {
+		bs->enemy = -1;
+		return;
+	}
 
 	//
 	reactiontime = botCharacterStatsManager.Characteristic_BFloat( bs->character, CHARACTERISTIC_REACTIONTIME, 0, 1 );
diff --git a/src/mpgame/bots/BotAI_Battle_Attacked.cpp b/src/mpgame/bots/BotAI_Battle_Attacked.cpp
index 15c117b..a39244e 100644
--- a/src/mpgame/bots/BotAI_Battle_Attacked.cpp
+++ b/src/mpgame/bots/BotAI_Battle_Attacked.cpp
@@ -24,9 +24,10 @@ stateResult_t rvmBot::state_Attacked(const stateParms_t& parms) {
 	}
 
 	// Ensure the target is a player.
-	idPlayer *entinfo = gameLocal.entities[bs.enemy]->Cast<idPlayer>();
+	idPlayer *entinfo = BotPlayerForIndex( bs.enemy );
 	if (!entinfo)
 	{
+		bs.enemy = -1;
 		stateThread.SetState("state_SeekLTG");
 		return SRESULT_DONE;
 	}
diff --git a/src/mpgame/bots/BotAI_Battle_Fight.cpp b/src/mpgame/bots/BotAI_Battle_Fight.cpp
index 719de68..7a41ae5 100644
--- a/src/mpgame/bots/BotAI_Battle_Fight.cpp
+++ b/src/mpgame/bots/BotAI_Battle_Fight.cpp
@@ -29,14 +29,20 @@ stateResult_t rvmBot::state_BattleFight(const stateParms_t& parms)
 	}
 
 	//if no enemy
-	if( bs.enemy < 0 )
+	if( bs.enemy < 0 || BotEntityForIndex( bs.enemy ) == NULL )
 	{
+		bs.enemy = -1;
 		stateThread.SetState("state_SeekLTG");
 		return SRESULT_DONE;
 	}
 
 	//BotEntityInfo(bs.enemy, &entinfo);
-	entinfo = gameLocal.entities[bs.enemy]->Cast<idPlayer>();// &g_entities[bs.enemy];
+	entinfo = BotPlayerForIndex( bs.enemy );// &g_entities[bs.enemy];
+	if ( entinfo == NULL ) {
+		bs.enemy = -1;
+		stateThread.SetState("state_SeekLTG");
+		return SRESULT_DONE;
+	}
 
 	//if the enemy is dead
 	if( bs.enemydeath_time )
diff --git a/src/mpgame/bots/BotAI_Battle_NBG.cpp b/src/mpgame/bots/BotAI_Battle_NBG.cpp
index e825a3a..53c4091 100644
--- a/src/mpgame/bots/BotAI_Battle_NBG.cpp
+++ b/src/mpgame/bots/BotAI_Battle_NBG.cpp
@@ -15,7 +15,7 @@ stateResult_t rvmBot::state_BattleNBG(const stateParms_t& parms)
 	int areanum;
 	bot_goal_t goal;
 	//aas_entityinfo_t entinfo;
-	idEntity* entinfo;
+	idPlayer* entinfo;
 	//bot_moveresult_t moveresult;
 	float attack_skill;
 	idVec3 target, dir;
@@ -38,14 +38,20 @@ stateResult_t rvmBot::state_BattleNBG(const stateParms_t& parms)
 	}
 
 	// if no enemy.
-	if( bs.enemy < 0 )
+	if( bs.enemy < 0 || BotEntityForIndex( bs.enemy ) == NULL )
 	{
+		bs.enemy = -1;
 		stateThread.SetState("state_SeekLTG");
 		return SRESULT_DONE;
 	}
 
 	//BotEntityInfo(bs.enemy, &entinfo);
-	entinfo = gameLocal.entities[bs.enemy]->Cast<idPlayer>();
+	entinfo = BotPlayerForIndex( bs.enemy );
+	if ( entinfo == NULL ) {
+		bs.enemy = -1;
+		stateThread.SetState("state_SeekNBG");
+		return SRESULT_DONE;
+	}
 	if( entinfo->health <= 0 )
 	{
 		//AIEnter_Seek_NBG(bs, "battle nbg: enemy dead");
diff --git a/src/mpgame/bots/BotAI_Battle_Retreat.cpp b/src/mpgame/bots/BotAI_Battle_Retreat.cpp
index eaaf1ff..a0b8b91 100644
--- a/src/mpgame/bots/BotAI_Battle_Retreat.cpp
+++ b/src/mpgame/bots/BotAI_Battle_Retreat.cpp
@@ -14,7 +14,6 @@ stateResult_t rvmBot::state_Retreat(const stateParms_t& parms)
 {
 	bot_goal_t goal;
 	idPlayer* entinfo;
-	rvmBot* owner;
 	idVec3 target, dir;
 	float attack_skill, range;
 
@@ -26,22 +25,22 @@ stateResult_t rvmBot::state_Retreat(const stateParms_t& parms)
 	}
 
 	// if no enemy.
-	if( bs.enemy < 0 )
+	if( bs.enemy < 0 || BotEntityForIndex( bs.enemy ) == NULL )
 	{
+		bs.enemy = -1;
 		stateThread.SetState("state_SeekLTG");
 		return SRESULT_DONE;
 	}
 
 	// Ensure the target is a player.
-	entinfo = gameLocal.entities[bs.enemy]->Cast<idPlayer>();
+	entinfo = BotPlayerForIndex( bs.enemy );
 	if( !entinfo )
 	{
+		bs.enemy = -1;
 		stateThread.SetState("state_SeekLTG");
 		return SRESULT_DONE;
 	}
 
-	owner = gameLocal.entities[bs.entitynum]->Cast<rvmBot>();
-
 	// If our enemy is dead, search for another LTG.
 	if( EntityIsDead( entinfo ) )
 	{
