Index: src/atom.cpp
===================================================================
--- src/atom.cpp	(revision bf8e2011562f9d20279686ee614b46b1841057b6)
+++ src/atom.cpp	(revision 0ba4103fb29b3b7e601800e6a20213e08ebef164)
@@ -19,4 +19,5 @@
 
 #include <iomanip>
+#include <iostream>
 
 /************************************* Functions for class atom *************************************/
@@ -165,9 +166,11 @@
   * \return true - \a *out present, false - \a *out is NULL
  */
-bool atom::OutputArrayIndexed(ostream * const out, const int *ElementNo, int *AtomNo, const char *comment) const
+bool atom::OutputArrayIndexed(ostream * const out,const enumeration<const element*> &elementLookup, int *AtomNo, const char *comment) const
 {
   AtomNo[type->Z]++;  // increment number
   if (out != NULL) {
-    *out << "Ion_Type" << ElementNo[type->Z] << "_" << AtomNo[type->Z] << "\t"  << fixed << setprecision(9) << showpoint;
+    cout << "Looking for atom with element " << *type << endl;
+    ASSERT(elementLookup.there.find(type)!=elementLookup.there.end(),"Type of this atom was not in the formula upon enumeration");
+    *out << "Ion_Type" << elementLookup.there.find(type)->second << "_" << AtomNo[type->Z] << "\t"  << fixed << setprecision(9) << showpoint;
     *out << x[0] << "\t" << x[1] << "\t" << x[2];
     *out << "\t" << FixedIon;
Index: src/atom.hpp
===================================================================
--- src/atom.hpp	(revision bf8e2011562f9d20279686ee614b46b1841057b6)
+++ src/atom.hpp	(revision 0ba4103fb29b3b7e601800e6a20213e08ebef164)
@@ -52,5 +52,5 @@
 
   bool OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment = NULL) const;
-  bool OutputArrayIndexed(ostream * const out, const int *ElementNo, int *AtomNo, const char *comment = NULL) const;
+  bool OutputArrayIndexed(ostream * const out,const enumeration<const element*>&, int *AtomNo, const char *comment = NULL) const;
   bool OutputXYZLine(ofstream *out) const;
   bool OutputTrajectory(ofstream * const out, const int *ElementNo, int *AtomNo, const int step) const;
Index: src/molecule.cpp
===================================================================
--- src/molecule.cpp	(revision bf8e2011562f9d20279686ee614b46b1841057b6)
+++ src/molecule.cpp	(revision 0ba4103fb29b3b7e601800e6a20213e08ebef164)
@@ -860,23 +860,18 @@
  * \param *out output stream
  */
-bool molecule::Output(ofstream * const output)
-{
-  int ElementNo[MAX_ELEMENTS], AtomNo[MAX_ELEMENTS];
-
-  for (int i=0;i<MAX_ELEMENTS;++i) {
-    AtomNo[i] = 0;
-    ElementNo[i] = 0;
-  }
+bool molecule::Output(ostream * const output)
+{
   if (output == NULL) {
     return false;
   } else {
+    int AtomNo[MAX_ELEMENTS];
+    memset(AtomNo,0,(MAX_ELEMENTS-1)*sizeof(*AtomNo));
+    enumeration<const element*> elementLookup = formula.enumerateElements();
+    for(map<const element*,unsigned int>::iterator iter=elementLookup.there.begin();
+        iter!=elementLookup.there.end();++iter){
+      cout << "Enumerated element " << *iter->first << " with number " << iter->second << endl;
+    }
     *output << "#Ion_TypeNr._Nr.R[0]    R[1]    R[2]    MoveType (0 MoveIon, 1 FixedIon)" << endl;
-    SetIndexedArrayForEachAtomTo ( ElementNo, &element::Z, &AbsoluteValue, 1);
-    int current=1;
-    for (int i=0;i<MAX_ELEMENTS;++i) {
-      if (ElementNo[i] == 1)
-        ElementNo[i] = current++;
-    }
-    ActOnAllAtoms( &atom::OutputArrayIndexed, (ostream * const) output, (const int *)ElementNo, (int *)AtomNo, (const char *) NULL );
+    for_each(atoms.begin(),atoms.end(),boost::bind(&atom::OutputArrayIndexed,_1,output,elementLookup,AtomNo,(const char*)0));
     return true;
   }
Index: src/molecule.hpp
===================================================================
--- src/molecule.hpp	(revision bf8e2011562f9d20279686ee614b46b1841057b6)
+++ src/molecule.hpp	(revision 0ba4103fb29b3b7e601800e6a20213e08ebef164)
@@ -341,5 +341,5 @@
 
   // Output routines.
-  bool Output(ofstream * const output);
+  bool Output(std::ostream * const output);
   bool OutputTrajectories(ofstream * const output);
   void OutputListOfBonds() const;
