diff --git a/src/action/action_demolish.cpp b/src/action/action_demolish.cpp
index a295e68a5..481e97db1 100644
--- a/src/action/action_demolish.cpp
+++ b/src/action/action_demolish.cpp
@@ -67,7 +67,9 @@ global void HandleActionDemolish(Unit* unit)
 		if( goal ) {
 		    if( goal->Destroyed ) {
 			DebugLevel0Fn("Destroyed unit\n");
+#ifdef REFS_DEBUG
 			DebugCheck( !goal->Refs );
+#endif
 			if( !--goal->Refs ) {
 			    ReleaseUnit(goal);
 			}
@@ -77,9 +79,13 @@ global void HandleActionDemolish(Unit* unit)
 			return;
 		    } else if( goal->Removed || !goal->HP
 				|| goal->Command.Action==UnitActionDie ) {
+#ifdef REFS_DEBUG
 			DebugCheck( !goal->Refs );
+#endif
 			--goal->Refs;
+#ifdef REFS_DEBUG
 			DebugCheck( !goal->Refs );
+#endif
 			unit->Command.Data.Move.Goal=goal=NoUnitP;
 			// FIXME: perhaps I should choose an alternative
 			unit->Command.Action=UnitActionStill;
@@ -113,9 +119,13 @@ global void HandleActionDemolish(Unit* unit)
 	case 1:
 	    goal=unit->Command.Data.Move.Goal;
 	    if( goal ) {
+#ifdef REFS_DEBUG
 		DebugCheck( !goal->Refs );
+#endif
 		--goal->Refs;
+#ifdef REFS_DEBUG
 		DebugCheck( !goal->Refs );
+#endif
 		unit->Command.Data.Move.Goal=NoUnitP;
 	    }
 
diff --git a/src/action/action_harvest.cpp b/src/action/action_harvest.cpp
index 93c1773a6..a6a492ef4 100644
--- a/src/action/action_harvest.cpp
+++ b/src/action/action_harvest.cpp
@@ -256,7 +256,9 @@ local int ReturnWithWood(Unit* unit)
     if( destu ) {
 	if( destu->Destroyed ) {
 	    DebugLevel0Fn("Destroyed unit\n");
+#ifdef REFS_DEBUG
 	    DebugCheck( !destu->Refs );
+#endif
 	    if( !--destu->Refs ) {
 		ReleaseUnit(destu);
 	    }
@@ -266,18 +268,26 @@ local int ReturnWithWood(Unit* unit)
 	    return 0;
 	} else if( destu->Removed || !destu->HP
 		    || destu->Command.Action==UnitActionDie ) {
+#ifdef REFS_DEBUG
 	    DebugCheck( !destu->Refs );
+#endif
 	    --destu->Refs;
+#ifdef REFS_DEBUG
 	    DebugCheck( !destu->Refs );
+#endif
 	    unit->Command.Data.Move.Goal=NoUnitP;
 	    // FIXME: perhaps I should choose an alternative
 	    unit->Command.Action=UnitActionStill;
 	    return 0;
 	}
 	unit->Command.Data.Move.Goal=NoUnitP;
+#ifdef REFS_DEBUG
 	DebugCheck( !destu->Refs );
+#endif
 	--destu->Refs;
+#ifdef REFS_DEBUG
 	DebugCheck( !destu->Refs );
+#endif
     }
 
     x=unit->Command.Data.Move.DX;
diff --git a/src/action/action_hauloil.cpp b/src/action/action_hauloil.cpp
index a993ae03d..ba481da43 100644
--- a/src/action/action_hauloil.cpp
+++ b/src/action/action_hauloil.cpp
@@ -10,7 +10,7 @@
 //
 /**@name action_hauloil.c -	The haul oil action. */
 //
-//	(c) Copyright 1998-2000 by Lutz Sammer
+//	(c) Copyright 1998-2001 by Lutz Sammer
 //
 //	$Id$
 
@@ -62,7 +62,9 @@ local int MoveToOilWell(Unit* unit)
 
     well=unit->Command.Data.Move.Goal;
     if( well && (well->Destroyed || !well->HP) ) {
+#ifdef REFS_DEBUG
 	DebugCheck( !well->Refs );
+#endif
 	if( !--well->Refs ) {
 	    ReleaseUnit(well);
 	}
@@ -84,9 +86,13 @@ local int MoveToOilWell(Unit* unit)
 	return -1;
     }
 
+#ifdef REFS_DEBUG
     DebugCheck( !well->Refs );
+#endif
     --well->Refs;
+#ifdef REFS_DEBUG
     DebugCheck( !well->Refs );
+#endif
     unit->Command.Data.Move.Goal=NoUnitP;
 
     //
@@ -255,7 +261,9 @@ local int MoveToOilDepot(Unit* unit)
 
     depot=unit->Command.Data.Move.Goal;
     if( depot && (depot->Destroyed || !depot->HP) ) {
+#ifdef REFS_DEBUG
 	DebugCheck( !depot->Refs );
+#endif
 	if( !--depot->Refs ) {
 	    ReleaseUnit(depot);
 	}
@@ -275,9 +283,13 @@ local int MoveToOilDepot(Unit* unit)
 
     DebugCheck( MapDistanceToUnit(unit->X,unit->Y,depot)!=1 );
 
+#ifdef REFS_DEBUG
     DebugCheck( !depot->Refs );
+#endif
     --depot->Refs;
+#ifdef REFS_DEBUG
     DebugCheck( !depot->Refs );
+#endif
     // FIXME: don't work unit->Command.Data.Move.Goal=NoUnitP;
 
     RemoveUnit(unit);
@@ -389,9 +401,13 @@ global void HandleActionHaulOil(Unit* unit)
 			unit->Command.Action=UnitActionStill;
 			unit->SubAction=0;
 			if( unit->Command.Data.Move.Goal ) {
+#ifdef REFS_DEBUG
 			    DebugCheck( !unit->Command.Data.Move.Goal->Refs );
+#endif
 			    --unit->Command.Data.Move.Goal->Refs;
+#ifdef REFS_DEBUG
 			    DebugCheck( !unit->Command.Data.Move.Goal->Refs );
+#endif
 			    unit->Command.Data.Move.Goal=NoUnitP;
 			}
 		    }
@@ -418,9 +434,13 @@ global void HandleActionHaulOil(Unit* unit)
 			unit->Command.Action=UnitActionStill;
 			unit->SubAction=0;
 			if( unit->Command.Data.Move.Goal ) {
+#ifdef REFS_DEBUG
 			    DebugCheck( !unit->Command.Data.Move.Goal->Refs );
+#endif
 			    --unit->Command.Data.Move.Goal->Refs;
+#ifdef REFS_DEBUG
 			    DebugCheck( !unit->Command.Data.Move.Goal->Refs );
+#endif
 			    unit->Command.Data.Move.Goal=NoUnitP;
 			}
 		    }
diff --git a/src/action/action_minegold.cpp b/src/action/action_minegold.cpp
index d78d3be8a..6248289b4 100644
--- a/src/action/action_minegold.cpp
+++ b/src/action/action_minegold.cpp
@@ -10,7 +10,7 @@
 //
 /**@name action_minegold.c -	The mine gold action. */
 //
-//	(c) Copyright 1998-2000 by Lutz Sammer
+//	(c) Copyright 1998-2001 by Lutz Sammer
 //
 //	$Id$
 
@@ -59,7 +59,9 @@ local int MoveToGoldMine(Unit* unit)
     destu=unit->Command.Data.Move.Goal;
     if( destu && (destu->Destroyed || !destu->HP) ) {
 	DebugLevel1Fn("WAIT after goldmine destroyed %d\n",unit->Wait);
+#ifdef REFS_DEBUG
 	DebugCheck( !destu->Refs );
+#endif
 	if( !--destu->Refs ) {
 	    ReleaseUnit(destu);
 	}
@@ -78,9 +80,13 @@ local int MoveToGoldMine(Unit* unit)
     //
     // FIXME: hmmm... we're in trouble here.
     // we should check if there's still some gold left in the mine instead.
+#ifdef REFS_DEBUG
     DebugCheck( !destu->Refs );
+#endif
     --destu->Refs;
+#ifdef REFS_DEBUG
     DebugCheck( !destu->Refs );
+#endif
     unit->Command.Data.Move.Goal=NoUnitP;
 
     destu->Command.Data.GoldMine.Active++;
@@ -234,7 +240,9 @@ local int MoveToGoldDeposit(Unit* unit)
 
     destu=unit->Command.Data.Move.Goal;
     if( destu && (destu->Destroyed || !destu->HP) ) {
+#ifdef REFS_DEBUG
 	DebugCheck( !destu->Refs );
+#endif
 	if( !--destu->Refs ) {
 	    ReleaseUnit(destu);
 	}
@@ -254,9 +262,13 @@ local int MoveToGoldDeposit(Unit* unit)
 	return -1;
     }
 
+#ifdef REFS_DEBUG
     DebugCheck( !destu->Refs );
+#endif
     --destu->Refs;
+#ifdef REFS_DEBUG
     DebugCheck( !destu->Refs );
+#endif
 
     RemoveUnit(unit);
     unit->X=destu->X;
@@ -375,9 +387,13 @@ global void HandleActionMineGold(Unit* unit)
 			unit->Command.Action=UnitActionStill;
 			unit->SubAction=0;
 			if( unit->Command.Data.Move.Goal ) {
+#ifdef REFS_DEBUG
 			    DebugCheck( !unit->Command.Data.Move.Goal->Refs );
+#endif
 			    --unit->Command.Data.Move.Goal->Refs;
+#ifdef REFS_DEBUG
 			    DebugCheck( !unit->Command.Data.Move.Goal->Refs );
+#endif
 			    unit->Command.Data.Move.Goal=NoUnitP;
 			}
 		    }
@@ -409,9 +425,13 @@ global void HandleActionMineGold(Unit* unit)
 			unit->Command.Action=UnitActionStill;
 			unit->SubAction=0;
 			if( unit->Command.Data.Move.Goal ) {
+#ifdef REFS_DEBUG
 			    DebugCheck( !unit->Command.Data.Move.Goal->Refs );
+#endif
 			    --unit->Command.Data.Move.Goal->Refs;
+#ifdef REFS_DEBUG
 			    DebugCheck( !unit->Command.Data.Move.Goal->Refs );
+#endif
 			    unit->Command.Data.Move.Goal=NoUnitP;
 			}
 		    }
diff --git a/src/action/action_move.cpp b/src/action/action_move.cpp
index 21ea5fe9d..b64b892fa 100644
--- a/src/action/action_move.cpp
+++ b/src/action/action_move.cpp
@@ -10,7 +10,7 @@
 //
 /**@name action_move.c	-	The move action. */
 //
-//	(c) Copyright 1998,2000 by Lutz Sammer
+//	(c) Copyright 1998,2001 by Lutz Sammer
 //
 //	$Id$
 
@@ -82,7 +82,9 @@ local int ActionMoveGeneric(Unit* unit,const Animation* move)
 	    // FIXME: Can't choose a better target here!
 	    if( goal->Destroyed ) {
 		DebugLevel0Fn("destroyed unit\n");
+#ifdef REFS_DEBUG
 		DebugCheck( !goal->Refs );
+#endif
 		if( !--goal->Refs ) {
 		    ReleaseUnit(goal);
 		}
@@ -90,9 +92,13 @@ local int ActionMoveGeneric(Unit* unit,const Animation* move)
 	    } else if( goal->Removed ||
 		    !goal->HP || goal->Command.Action==UnitActionDie ) {
 		DebugLevel0Fn("killed unit\n");
+#ifdef REFS_DEBUG
 		DebugCheck( !goal->Refs );
+#endif
 		--goal->Refs;
+#ifdef REFS_DEBUG
 		DebugCheck( !goal->Refs );
+#endif
 		unit->Command.Data.Move.Goal=goal=NoUnitP;
 	    }
 	}
diff --git a/src/action/action_repair.cpp b/src/action/action_repair.cpp
index 38f90a35d..6dfabc1ee 100644
--- a/src/action/action_repair.cpp
+++ b/src/action/action_repair.cpp
@@ -10,7 +10,7 @@
 //
 /**@name action_repair.c	-	The repair action. */
 //
-//	(c) Copyright 1999,2000 by Vladi Shabanski
+//	(c) Copyright 1999-2001 by Vladi Shabanski
 //
 //	$Id$
 
@@ -172,7 +172,9 @@ global int HandleActionRepair(Unit* unit)
 		if( goal ) {
 		    if( goal->Destroyed ) {
 			DebugLevel0Fn("destroyed unit\n");
+#ifdef REFS_DEBUG
 			DebugCheck( !goal->Refs );
+#endif
 			if( !--goal->Refs ) {
 			    ReleaseUnit(goal);
 			}
@@ -183,9 +185,13 @@ global int HandleActionRepair(Unit* unit)
 		    } else if( !goal->HP ||
 				goal->Command.Action==UnitActionDie ) {
 
+#ifdef REFS_DEBUG
 			DebugCheck( !goal->Refs );
+#endif
 			--goal->Refs;
+#ifdef REFS_DEBUG
 			DebugCheck( !goal->Refs );
+#endif
 			// FIXME: should I clear this here?
 			unit->Command.Data.Move.Goal=goal=NULL;
 			unit->Command.Data.Move.DX=goal->X;
@@ -202,9 +208,13 @@ global int HandleActionRepair(Unit* unit)
 		} else if( err<0 ) {
 		    DebugCheck( unit->Command.Action!=UnitActionStill );
 		    if( goal ) {		// release reference
+#ifdef REFS_DEBUG
 			DebugCheck( !goal->Refs );
+#endif
 			goal->Refs--;
+#ifdef REFS_DEBUG
 			DebugCheck( !goal->Refs );
+#endif
 			unit->Command.Data.Move.Goal=NoUnitP;
 		    }
 		    return 1;
@@ -229,7 +239,9 @@ global int HandleActionRepair(Unit* unit)
 		if( goal ) {
 		    if( goal->Destroyed ) {
 			DebugLevel0Fn("destroyed unit\n");
+#ifdef REFS_DEBUG
 			DebugCheck( !goal->Refs );
+#endif
 			if( !--goal->Refs ) {
 			    ReleaseUnit(goal);
 			}
@@ -254,9 +266,13 @@ global int HandleActionRepair(Unit* unit)
 		//
 		if( !goal || goal->HP >= goal->Stats->HitPoints ) {
 		    if( goal ) {		// release reference
+#ifdef REFS_DEBUG
 			DebugCheck( !goal->Refs );
+#endif
 			goal->Refs--;
+#ifdef REFS_DEBUG
 			DebugCheck( !goal->Refs );
+#endif
 			unit->Command.Data.Move.Goal=NULL;
 		    }
                     unit->Command.Action=UnitActionStill;
diff --git a/src/action/action_spellcast.cpp b/src/action/action_spellcast.cpp
index e410afc1c..65f4ce79c 100644
--- a/src/action/action_spellcast.cpp
+++ b/src/action/action_spellcast.cpp
@@ -9,11 +9,10 @@
 //	   FreeCraft - A free fantasy real time strategy game engine
 //
 /**@name action_spellcast.c	-	The spell cast action. */
-/*
-**	(c) Copyright 1998-2000 by Vladi Belperchinov-Shabanski
-**
-**	$Id$
-*/
+//
+//	(c) Copyright 1998-2001 by Vladi Belperchinov-Shabanski
+//
+//	$Id$
 
 /*
 ** This is inherited from action_attack.c, actually spell casting will
@@ -162,7 +161,13 @@ global void HandleActionSpellCast(Unit* unit)
 		     unit->SubAction=0;
 		     unit->Wait = 1;
 		     if ( unit->Command.Data.Move.Goal )
+#ifdef REFS_DEBUG
+			DebugCheck( !unit->Command.Data.Move.Goal->Refs );
+#endif
 		        unit->Command.Data.Move.Goal->Refs--;
+#ifdef REFS_DEBUG
+			DebugCheck( !unit->Command.Data.Move.Goal->Refs );
+#endif
 		  }
 		}
 	    break;
diff --git a/src/action/action_still.cpp b/src/action/action_still.cpp
index 63d30a1e0..1936b8a49 100644
--- a/src/action/action_still.cpp
+++ b/src/action/action_still.cpp
@@ -10,7 +10,7 @@
 //
 /**@name action_still.c	-	The stand still action. */
 //
-//	(c) Copyright 1998,2000 by Lutz Sammer
+//	(c) Copyright 1998,2000,2001 by Lutz Sammer
 //
 //	$Id$
 
@@ -163,7 +163,9 @@ global void ActionStillGeneric(Unit* unit,int ground)
 	    if( temp && temp->Destroyed ) {
 		DebugLevel3Fn(" destroyed unit %Zd #%d\n"
 			,UnitNumber(temp),temp->Refs);
+#ifdef REFS_DEBUG
 		DebugCheck( !temp->Refs );
+#endif
 		if( !--temp->Refs ) {
 		    ReleaseUnit(temp);
 		}
@@ -174,9 +176,13 @@ global void ActionStillGeneric(Unit* unit,int ground)
 		if( temp ) {
 		    DebugLevel3Fn(" old unit %Zd #%d\n"
 			    ,UnitNumber(temp),temp->Refs);
+#ifdef REFS_DEBUG
 		    DebugCheck( !temp->Refs );
+#endif
 		    temp->Refs--;
+#ifdef REFS_DEBUG
 		    DebugCheck( !temp->Refs );
+#endif
 		}
 		unit->Command.Data.Move.Goal=goal;
 		goal->Refs++;
@@ -194,9 +200,13 @@ global void ActionStillGeneric(Unit* unit,int ground)
 
     if( unit->SubAction ) {		// was attacking.
 	if( (temp=unit->Command.Data.Move.Goal) ) {
+#ifdef REFS_DEBUG
 	    DebugCheck( !temp->Refs );
+#endif
 	    temp->Refs--;
+#ifdef REFS_DEBUG
 	    DebugCheck( !temp->Refs );
+#endif
 	    unit->Command.Data.Move.Goal=NoUnitP;
 	}
 	unit->SubAction=unit->State=0;
diff --git a/src/action/action_unload.cpp b/src/action/action_unload.cpp
index 4d7978c52..69c30ed5d 100644
--- a/src/action/action_unload.cpp
+++ b/src/action/action_unload.cpp
@@ -84,15 +84,21 @@ local void LeaveTransporter(Unit* unit)
 	unit->Command.Data.Move.Goal=NoUnitP;
 	if( goal->Destroyed ) {
 	    DebugLevel0Fn("destroyed unit\n");
+#ifdef REFS_DEBUG
 	    DebugCheck( !goal->Refs );
+#endif
 	    if( !--goal->Refs ) {
 		ReleaseUnit(goal);
 	    }
 	    return;
 	}
+#ifdef REFS_DEBUG
 	DebugCheck( !goal->Refs );
+#endif
 	--goal->Refs;
+#ifdef REFS_DEBUG
 	DebugCheck( !goal->Refs );
+#endif
 	for( i=0; i<MAX_UNITS_ONBOARD; ++i ) {
 	    if( goal==unit->OnBoard[i] ) {
 		goal->X=unit->X;
diff --git a/src/action/actions.cpp b/src/action/actions.cpp
index 14097367c..6757eb674 100644
--- a/src/action/actions.cpp
+++ b/src/action/actions.cpp
@@ -10,7 +10,7 @@
 //
 /**@name actions.c	-	The actions. */
 //
-//	(c) Copyright 1998,2000 by Lutz Sammer
+//	(c) Copyright 1998,2000,2001 by Lutz Sammer
 //
 //	$Id$
 
@@ -119,7 +119,9 @@ local void HandleUnitAction(Unit* unit)
 	    //	Release pending references.
 	    //
 	    if( unit->Command.Data.Move.Goal ) {
+#ifdef REFS_DEBUG
 		DebugCheck( !unit->Command.Data.Move.Goal->Refs-- );
+#endif
 		if !--unit->Command.Data.Move.Goal->Refs ) {
 		    ReleaseUnit(unit->Command.Data.Move.Goal);
 		}