Index: src/Actions/Action.cpp
===================================================================
--- src/Actions/Action.cpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/Action.cpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -13,8 +13,7 @@
 using namespace std;
 
-// this object is only ever used as indicator.
-ActionState success_val;
-
-ActionState *Action::success = &success_val;
+// An empty state to indicate success
+Action::state_ptr Action::success = Action::state_ptr(new ActionState());
+Action::state_ptr Action::failure = Action::state_ptr(new ActionState());
 
 Action::Action(std::string _name,bool _doRegister) :
@@ -37,9 +36,9 @@
   performCall();
 }
-ActionState* Action::undo(ActionState* _state) {
+Action::state_ptr Action::undo(state_ptr _state) {
   // forward to private virtual
   return performUndo(_state);
 }
-ActionState* Action::redo(ActionState* _state) {
+Action::state_ptr Action::redo(state_ptr _state) {
   // forward to private virtual
   return performRedo(_state);
Index: src/Actions/Action.hpp
===================================================================
--- src/Actions/Action.hpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/Action.hpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -10,4 +10,5 @@
 
 #include <string>
+#include <boost/shared_ptr.hpp>
 
 // forward declaration
@@ -28,4 +29,7 @@
 friend class ActionSequence;
 public:
+
+  typedef boost::shared_ptr<ActionState> state_ptr;
+
   Action(std::string _name,bool _doRegister=true);
   virtual ~Action();
@@ -34,6 +38,6 @@
   // actuall action is passed on to a private virtual
   void call();
-  ActionState* undo(ActionState*);
-  ActionState* redo(ActionState*);
+  state_ptr undo(state_ptr);
+  state_ptr redo(state_ptr);
 
   virtual bool canUndo()=0;
@@ -43,10 +47,11 @@
 
 protected:
-  static ActionState* success;
+  static state_ptr success;
+  static state_ptr failure;
 
 private:
-  virtual ActionState* performCall()=0;
-  virtual ActionState* performUndo(ActionState*)=0;
-  virtual ActionState* performRedo(ActionState*)=0;
+  virtual state_ptr performCall()=0;
+  virtual state_ptr performUndo(state_ptr)=0;
+  virtual state_ptr performRedo(state_ptr)=0;
 
   std::string name;
Index: src/Actions/ActionSequence.cpp
===================================================================
--- src/Actions/ActionSequence.cpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/ActionSequence.cpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -41,5 +41,5 @@
     // we want to have a global bookkeeping for all actions in the sequence, so
     // we bypass the normal call
-    ActionState *state = (*it)->performCall();
+    Action::state_ptr state = (*it)->performCall();
     states.push_back(state);
   }
@@ -47,5 +47,5 @@
 }
 
-ActionSequence::stateSet ActionSequence::undoAll(deque<ActionState*> states){
+ActionSequence::stateSet ActionSequence::undoAll(stateSet states){
   ASSERT(canUndo(),"Trying to undo a sequence that contains methods that can't be undone");
   stateSet res;
@@ -55,5 +55,5 @@
     ASSERT(stateRit!=states.rend(),"End of states prematurely reached.");
     if((*actionRit)->shouldUndo()){
-      ActionState *newState = (*actionRit)->performUndo(*stateRit);
+      Action::state_ptr newState = (*actionRit)->performUndo(*stateRit);
       // The order of the states has to correspond to the order of the actions
       // this is why we have to add at the beginning
@@ -67,5 +67,5 @@
 }
 
-ActionSequence::stateSet ActionSequence::redoAll(deque<ActionState*> states){
+ActionSequence::stateSet ActionSequence::redoAll(stateSet states){
   stateSet res;
   actionSet::iterator actionIt = actions.begin();
@@ -74,5 +74,5 @@
     ASSERT(stateIt!=states.end(),"End of states prematurely reached.");
     if((*actionIt)->shouldUndo()){
-      ActionState *newState =(*actionIt)->performRedo(*stateIt);
+      Action::state_ptr newState =(*actionIt)->performRedo(*stateIt);
       res.push_back(newState);
     }
Index: src/Actions/ActionSequence.hpp
===================================================================
--- src/Actions/ActionSequence.hpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/ActionSequence.hpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -9,8 +9,7 @@
 #define ACTIONSEQUENZE_HPP_
 
+#include "Actions/Action.hpp"
+
 #include <deque>
-
-class Action;
-class ActionState;
 
 /**
@@ -21,5 +20,5 @@
 public:
   typedef std::deque<Action*> actionSet;
-  typedef std::deque<ActionState*> stateSet;
+  typedef std::deque<Action::state_ptr> stateSet;
 
   ActionSequence();
Index: src/Actions/Calculation.hpp
===================================================================
--- src/Actions/Calculation.hpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/Calculation.hpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -64,7 +64,7 @@
   virtual T* doCalc()=0;
 private:
-  virtual ActionState* performCall();
-  virtual ActionState* performUndo(ActionState*);
-  virtual ActionState* performRedo(ActionState*);
+  virtual Action::state_ptr performCall();
+  virtual Action::state_ptr performUndo(Action::state_ptr);
+  virtual Action::state_ptr performRedo(Action::state_ptr);
 
   bool done;
Index: src/Actions/Calculation_impl.hpp
===================================================================
--- src/Actions/Calculation_impl.hpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/Calculation_impl.hpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -29,5 +29,5 @@
 
 template<typename T>
-ActionState* Calculation<T>::performCall(){
+Action::state_ptr Calculation<T>::performCall(){
   reset();
   (*this)();
@@ -36,10 +36,10 @@
 
 template<typename T>
-ActionState* Calculation<T>::performUndo(ActionState*){
+Action::state_ptr Calculation<T>::performUndo(Action::state_ptr){
   ASSERT(0,"Cannot undo a calculation");
   return Action::success;
 }
 template<typename T>
-ActionState* Calculation<T>::performRedo(ActionState*){
+Action::state_ptr Calculation<T>::performRedo(Action::state_ptr){
   ASSERT(0,"Cannot redo a calculation");
   return Action::success;
Index: src/Actions/ErrorAction.cpp
===================================================================
--- src/Actions/ErrorAction.cpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/ErrorAction.cpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -25,14 +25,14 @@
 }
 
-ActionState* ErrorAction::performCall() {
+Action::state_ptr ErrorAction::performCall() {
   Log() << Verbose(0) << errorMsg << endl;
   return Action::success;
 }
-ActionState* ErrorAction::performUndo(ActionState*) {
+Action::state_ptr ErrorAction::performUndo(Action::state_ptr) {
   ASSERT(0,"Undo called for an ErrorAction");
   return Action::success;
 }
 
-ActionState* ErrorAction::performRedo(ActionState*) {
+Action::state_ptr ErrorAction::performRedo(Action::state_ptr) {
   ASSERT(0,"Redo called for an ErrorAction");
   return Action::success;
Index: src/Actions/ErrorAction.hpp
===================================================================
--- src/Actions/ErrorAction.hpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/ErrorAction.hpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -23,7 +23,7 @@
 private:
 
-  virtual ActionState* performCall();
-  virtual ActionState* performUndo(ActionState*);
-  virtual ActionState* performRedo(ActionState*);
+  virtual Action::state_ptr performCall();
+  virtual Action::state_ptr performUndo(Action::state_ptr);
+  virtual Action::state_ptr performRedo(Action::state_ptr);
 
   std::string errorMsg;
Index: src/Actions/MakroAction.cpp
===================================================================
--- src/Actions/MakroAction.cpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/MakroAction.cpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -21,8 +21,5 @@
   {}
   virtual ~MakroActionState(){
-    for(ActionSequence::stateSet::iterator iter=states.begin();
-        iter!=states.end();++iter){
-      delete *iter;
-    }
+    // All contained states are destroyed by the shared ptrs
   }
 
@@ -46,14 +43,21 @@
 
 
-ActionState* MakroAction::performCall(){
+Action::state_ptr MakroAction::performCall(){
   ActionSequence::stateSet states = actions->callAll();
-  return new MakroActionState(states);
+  return Action::state_ptr(new MakroActionState(states));
 }
 
-ActionState* MakroAction::performUndo(ActionState* _state) {
-  MakroActionState *state = dynamic_cast<MakroActionState*>(_state);
+Action::state_ptr MakroAction::performUndo(Action::state_ptr _state) {
+  MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get());
   ASSERT(state,"Type mismatch for the state of the MakroAction");
   ActionSequence::stateSet states = actions->undoAll(state->states);
-  return new MakroActionState(states);
+  return Action::state_ptr(new MakroActionState(states));
+}
+
+Action::state_ptr MakroAction::performRedo(Action::state_ptr _state){
+  MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get());
+  ASSERT(state,"Type mismatch for the state of the MakroAction");
+  ActionSequence::stateSet states = actions->redoAll(state->states);
+  return Action::state_ptr(new MakroActionState(states));
 }
 
Index: src/Actions/MakroAction.hpp
===================================================================
--- src/Actions/MakroAction.hpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/MakroAction.hpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -30,7 +30,7 @@
 
 private:
-  virtual ActionState* performCall();
-  virtual ActionState* performUndo(ActionState*);
-  virtual ActionState* performRedo(ActionState*);
+  virtual Action::state_ptr performCall();
+  virtual Action::state_ptr performUndo(Action::state_ptr);
+  virtual Action::state_ptr performRedo(Action::state_ptr);
 
   ActionSequence *actions;
Index: src/Actions/ManipulateAtomsProcess.cpp
===================================================================
--- src/Actions/ManipulateAtomsProcess.cpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/ManipulateAtomsProcess.cpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -25,15 +25,15 @@
 {}
 
-ActionState* ManipulateAtomsProcess::performCall(){
+Action::state_ptr ManipulateAtomsProcess::performCall(){
   World::getInstance().doManipulate(this);
   return Action::success;
 }
 
-ActionState* ManipulateAtomsProcess::performUndo(ActionState*){
+Action::state_ptr ManipulateAtomsProcess::performUndo(Action::state_ptr){
   ASSERT(0,"Undo called for a ManipulateAtomsProcess");
   return Action::success;
 }
 
-ActionState* ManipulateAtomsProcess::performRedo(ActionState*){
+Action::state_ptr ManipulateAtomsProcess::performRedo(Action::state_ptr){
   ASSERT(0,"Redo called for a ManipulateAtomsProcess");
   return Action::success;
Index: src/Actions/ManipulateAtomsProcess.hpp
===================================================================
--- src/Actions/ManipulateAtomsProcess.hpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/ManipulateAtomsProcess.hpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -29,7 +29,7 @@
 private:
 
-  virtual ActionState* performCall();
-  virtual ActionState* performUndo(ActionState*);
-  virtual ActionState* performRedo(ActionState*);
+  virtual Action::state_ptr performCall();
+  virtual Action::state_ptr performUndo(Action::state_ptr);
+  virtual Action::state_ptr performRedo(Action::state_ptr);
 
   AtomDescriptor descr;
Index: src/Actions/MethodAction.cpp
===================================================================
--- src/Actions/MethodAction.cpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/MethodAction.cpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -25,5 +25,5 @@
 
 
-ActionState* MethodAction::performCall() {
+Action::state_ptr MethodAction::performCall() {
   executeMethod();
   // we don't have a state to save so we return Action::success
@@ -31,10 +31,10 @@
 }
 
-ActionState* MethodAction::performUndo(ActionState*) {
+Action::state_ptr MethodAction::performUndo(Action::state_ptr) {
   ASSERT(0,"Cannot undo a MethodAction");
   return Action::success;
 }
 
-ActionState* MethodAction::performRedo(ActionState*){
+Action::state_ptr MethodAction::performRedo(Action::state_ptr){
   ASSERT(0,"Cannot redo a MethodAction");
   return Action::success;
Index: src/Actions/MethodAction.hpp
===================================================================
--- src/Actions/MethodAction.hpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/MethodAction.hpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -26,7 +26,7 @@
 
 private:
-  virtual ActionState* performCall();
-  virtual ActionState* performUndo(ActionState*);
-  virtual ActionState* performRedo(ActionState*);
+  virtual Action::state_ptr performCall();
+  virtual Action::state_ptr performUndo(Action::state_ptr);
+  virtual Action::state_ptr performRedo(Action::state_ptr);
 
 
Index: src/Actions/small_actions.cpp
===================================================================
--- src/Actions/small_actions.cpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/small_actions.cpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -36,5 +36,5 @@
 {}
 
-ActionState* ChangeMoleculeNameAction::performCall() {
+Action::state_ptr ChangeMoleculeNameAction::performCall() {
   string filename;
   molecule *mol = NULL;
@@ -48,11 +48,12 @@
     mol->setName(filename);
     delete dialog;
-    return new ChangeMoleculeNameState(mol,oldName);
+    return Action::state_ptr(new ChangeMoleculeNameState(mol,oldName));
   }
-  return 0;
+  delete dialog;
+  return Action::failure;
 }
 
-ActionState* ChangeMoleculeNameAction::performUndo(ActionState* _state) {
-  ChangeMoleculeNameState *state = dynamic_cast<ChangeMoleculeNameState*>(_state);
+Action::state_ptr ChangeMoleculeNameAction::performUndo(Action::state_ptr _state) {
+  ChangeMoleculeNameState *state = dynamic_cast<ChangeMoleculeNameState*>(_state.get());
   ASSERT(state,"State passed to ChangeMoleculeNameAction::performUndo did not have correct type");
 
@@ -60,8 +61,8 @@
   state->mol->setName(state->lastName);
 
-  return new ChangeMoleculeNameState(state->mol,newName);
+  return Action::state_ptr(new ChangeMoleculeNameState(state->mol,newName));
 }
 
-ActionState* ChangeMoleculeNameAction::performRedo(ActionState *_state){
+Action::state_ptr ChangeMoleculeNameAction::performRedo(Action::state_ptr _state){
   // Undo and redo have to do the same for this action
   return performUndo(_state);
Index: src/Actions/small_actions.hpp
===================================================================
--- src/Actions/small_actions.hpp	(revision 67e2b3572734296ec6d1bd4e7c867fa823cee04f)
+++ src/Actions/small_actions.hpp	(revision 5b0b98b2ea8b24976731e525dc2aa2811d18dc20)
@@ -19,7 +19,7 @@
   virtual const std::string getName();
 private:
-  virtual ActionState* performCall();
-  virtual ActionState* performUndo(ActionState*);
-  virtual ActionState* performRedo(ActionState*);
+  virtual Action::state_ptr performCall();
+  virtual Action::state_ptr performUndo(Action::state_ptr);
+  virtual Action::state_ptr performRedo(Action::state_ptr);
 
   MoleculeListClass *molecules;
