Index: src/Formula.cpp
===================================================================
--- src/Formula.cpp	(revision d03bb14106e04d88a0fafff8de40436be73197a1)
+++ src/Formula.cpp	(revision a6d6a964b111c9a4edb650b08d8aae44ad5d3f5a)
@@ -45,5 +45,7 @@
   stringstream sstr;
   for(const_reverse_iterator iter=rbegin();iter!=rend();++iter){
-    sstr << (*iter).first->symbol << (*iter).second;
+    sstr << (*iter).first->symbol;
+    if((*iter).second>1)
+      sstr << (*iter).second;
   }
   return sstr.str();
@@ -99,5 +101,5 @@
 }
 
-unsigned int Formula::getElementCount(){
+unsigned int Formula::getElementCount() const{
   return numElements;
 }
@@ -183,17 +185,18 @@
 }
 
-const unsigned int &Formula::operator[](const element *element) const{
+const unsigned int Formula::operator[](const element *element) const{
   ASSERT(element,"Invalid pointer in access of Formula");
   return operator[](element->getNumber());
 }
 
-const unsigned int &Formula::operator[](atomicNumber_t Z) const{
-  ASSERT(Z>0,"Invalid atomic Number");
-  ASSERT(World::getInstance().getPeriode()->FindElement(Z),"No Element with this number in Periodentafel");
-  elementCounts.resize(Z);   // No-op when we already have the right size
+const unsigned int Formula::operator[](atomicNumber_t Z) const{
+  ASSERT(Z>0,"Invalid atomic Number");
+  ASSERT(World::getInstance().getPeriode()->FindElement(Z),"No Element with this number in Periodentafel");
+  if(elementCounts.size()<Z)
+    return 0;
   return elementCounts[Z-1]; // atomic numbers start at 1
 }
 
-const unsigned int &Formula::operator[](string shorthand) const{
+const unsigned int Formula::operator[](string shorthand) const{
   element * element = World::getInstance().getPeriode()->FindElement(shorthand);
   return operator[](element);
@@ -263,6 +266,11 @@
 {
   ASSERT(pos<=set->size(),"invalid position in iterator construction");
-  while(pos<set->size() && (*set)[pos]!=0) ++pos;
-}
+  while(pos<set->size() && (*set)[pos]==0) ++pos;
+}
+
+template <class result_type>
+Formula::_iterator<result_type>::_iterator(const _iterator &rhs) :
+  set(rhs.set),pos(rhs.pos)
+{}
 
 template <class result_type>
@@ -293,6 +301,15 @@
 Formula::_iterator<result_type>::operator++(){
   ASSERT(pos!=set->size(),"Incrementing Formula::iterator beyond end");
-  while(pos<set->size() && (*set)[pos]!=0) ++pos;
+  pos++;
+  while(pos<set->size() && (*set)[pos]==0) ++pos;
   return *this;
+}
+
+template <class result_type>
+Formula::_iterator<result_type>
+Formula::_iterator<result_type>::operator++(int){
+  Formula::_iterator<result_type> retval = *this;
+  ++(*this);
+  return retval;
 }
 
@@ -300,7 +317,16 @@
 Formula::_iterator<result_type>
 Formula::_iterator<result_type>::operator--(){
-  ASSERT(pos!=0,"Decrementing Formula::iterator beyobd begin");
-  while(pos>0 && (*set)[pos]!=0) ++pos;
+  ASSERT(pos!=0,"Decrementing Formula::iterator beyond begin");
+  pos--;
+  while(pos>0 && (*set)[pos]==0) --pos;
   return *this;
+}
+
+template <class result_type>
+Formula::_iterator<result_type>
+Formula::_iterator<result_type>::operator--(int){
+  Formula::_iterator<result_type> retval = *this;
+  --(*this);
+  return retval;
 }
 
@@ -324,4 +350,37 @@
 }
 
+// explicit instantiation of all iterator template methods
+// this is quite ugly, but there is no better way unless we expose iterator implementation
+
+// instantiate Formula::iterator
+template Formula::_iterator<Formula::value_type>::_iterator(set_t&);
+template Formula::_iterator<Formula::value_type>::_iterator(set_t&,size_t);
+template Formula::_iterator<Formula::value_type>::_iterator(const Formula::_iterator<Formula::value_type>&);
+template Formula::_iterator<Formula::value_type>::~_iterator();
+template Formula::_iterator<Formula::value_type> &Formula::_iterator<Formula::value_type>::operator=(const _iterator &);
+template bool Formula::_iterator<Formula::value_type>::operator==(const _iterator&);
+template bool Formula::_iterator<Formula::value_type>::operator!=(const _iterator&);
+template Formula::_iterator<Formula::value_type> Formula::_iterator<Formula::value_type>::operator++();
+template Formula::_iterator<Formula::value_type> Formula::_iterator<Formula::value_type>::operator++(int);
+template Formula::_iterator<Formula::value_type> Formula::_iterator<Formula::value_type>::operator--();
+template Formula::_iterator<Formula::value_type> Formula::_iterator<Formula::value_type>::operator--(int);
+template Formula::value_type Formula::_iterator<Formula::value_type>::operator*();
+template Formula::value_type *Formula::_iterator<Formula::value_type>::operator->();
+
+// instantiate Formula::const_iterator
+template Formula::_iterator<const Formula::value_type>::_iterator(set_t&);
+template Formula::_iterator<const Formula::value_type>::_iterator(set_t&,size_t);
+template Formula::_iterator<const Formula::value_type>::_iterator(const Formula::_iterator<const Formula::value_type>&);
+template Formula::_iterator<const Formula::value_type>::~_iterator();
+template Formula::_iterator<const Formula::value_type> &Formula::_iterator<const Formula::value_type>::operator=(const _iterator &);
+template bool Formula::_iterator<const Formula::value_type>::operator==(const _iterator&);
+template bool Formula::_iterator<const Formula::value_type>::operator!=(const _iterator&);
+template Formula::_iterator<const Formula::value_type> Formula::_iterator<const Formula::value_type>::operator++();
+template Formula::_iterator<const Formula::value_type> Formula::_iterator<const Formula::value_type>::operator++(int);
+template Formula::_iterator<const Formula::value_type> Formula::_iterator<const Formula::value_type>::operator--();
+template Formula::_iterator<const Formula::value_type> Formula::_iterator<const Formula::value_type>::operator--(int);
+template const Formula::value_type Formula::_iterator<const Formula::value_type>::operator*();
+template const Formula::value_type *Formula::_iterator<const Formula::value_type>::operator->();
+
 /********************** I/O of Formulas ************************************************/
 
Index: src/Formula.hpp
===================================================================
--- src/Formula.hpp	(revision d03bb14106e04d88a0fafff8de40436be73197a1)
+++ src/Formula.hpp	(revision a6d6a964b111c9a4edb650b08d8aae44ad5d3f5a)
@@ -34,4 +34,5 @@
     _iterator(set_t&);
     _iterator(set_t&,size_t);
+    _iterator(const _iterator &rhs);
     ~_iterator();
     _iterator   &operator=(const _iterator &);
@@ -65,5 +66,5 @@
   bool checkOut(std::ostream*) const;
 
-  unsigned int getElementCount();
+  unsigned int getElementCount() const;
   bool hasElement(const element*)       const;
   bool hasElement(atomicNumber_t)       const;
@@ -84,7 +85,7 @@
   // only const versions, because someone might try to increment a previously
   // not set element
-  const unsigned int &operator[](const element*) const;
-  const unsigned int &operator[](atomicNumber_t) const;
-  const unsigned int &operator[](std::string)    const;
+  const unsigned int operator[](const element*) const;
+  const unsigned int operator[](atomicNumber_t) const;
+  const unsigned int operator[](std::string)    const;
 
   bool operator==(const Formula&) const;
