Index: libs/ardour/session_state.cc
===================================================================
--- libs/ardour/session_state.cc	(revision 5564)
+++ libs/ardour/session_state.cc	(working copy)
@@ -2151,10 +2151,12 @@
 {
 	UndoTransaction* trans = new UndoTransaction();
 	trans->set_name(name);
-
+	
 	if (!_current_trans.empty()) {
+		_current_trans.top()->inc_count();
 		_current_trans.top()->add_command (trans);
 	} else {
+		trans->inc_count();
 		_current_trans.push(trans);
 	}
 }
@@ -2164,12 +2166,13 @@
 {
 	assert(!_current_trans.empty());
 	struct timeval now;
-
+	
 	if (cmd) {
+		_current_trans.top()->dec_count();
 		_current_trans.top()->add_command(cmd);
 	}
 
-	if (_current_trans.top()->empty()) {
+	if (_current_trans.top()->empty()) { 
 		_current_trans.pop();
 		return;
 	}
@@ -2177,8 +2180,10 @@
 	gettimeofday(&now, 0);
 	_current_trans.top()->set_timestamp(now);
 
-	_history.add(_current_trans.top());
-	_current_trans.pop();
+	if(_current_trans.top()->count() == 0){ 
+		_history.add(_current_trans.top());
+		_current_trans.pop();
+	}
 }
 
 Session::GlobalRouteBooleanState 
Index: libs/pbd/undo.cc
===================================================================
--- libs/pbd/undo.cc	(revision 5564)
+++ libs/pbd/undo.cc	(working copy)
@@ -34,6 +34,7 @@
 	: _clearing(false)
 {
 	gettimeofday (&_timestamp, 0);
+	_count = 0;
 }
 
 UndoTransaction::UndoTransaction (const UndoTransaction& rhs)
@@ -42,6 +43,7 @@
 {
 	clear ();
 	actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end());
+	_count = 0;
 }
 
 UndoTransaction::~UndoTransaction ()
@@ -74,6 +76,30 @@
 	return *this;
 }
 
+int
+UndoTransaction::get_action_count ()
+{
+	return actions.size();
+}
+
+int
+UndoTransaction::count ()
+{
+	return _count;
+}
+
+int
+UndoTransaction::inc_count ()
+{
+	return _count++;
+}
+
+int
+UndoTransaction::dec_count ()
+{
+	return _count--;
+}
+
 void
 UndoTransaction::add_command (Command *const action)
 {
@@ -115,9 +141,6 @@
 UndoTransaction::clear ()
 {
 	_clearing = true;
-	for (list<Command*>::iterator i = actions.begin(); i != actions.end(); ++i) {
-		delete *i;
-	}
 	actions.clear ();
 	_clearing = false;
 }
Index: libs/pbd/pbd/undo.h
===================================================================
--- libs/pbd/pbd/undo.h	(revision 5564)
+++ libs/pbd/pbd/undo.h	(working copy)
@@ -41,7 +41,12 @@
 	void clear ();
 	bool empty() const;
 	bool clearing () const { return _clearing; }
-
+	
+	int inc_count ();
+	int dec_count ();
+	int count ();
+	
+	int get_action_count ();
 	void add_command (Command* const);
 	void remove_command (Command* const);
 
@@ -64,7 +69,8 @@
 	std::list<PBD::ProxyShiva<Command,UndoTransaction>*> shivas;
 	struct timeval        _timestamp;
 	bool                  _clearing;
-
+	int		      _count;
+	
 	friend void command_death (UndoTransaction*, Command *);
 	
 	friend class UndoHistory;
