From 21e64e113f3100b519ac4e0c1d78e67373f81c0b Mon Sep 17 00:00:00 2001
From: Jochem Snuverink <jochem.snuverink@psi.ch>
Date: Fri, 25 Sep 2020 11:47:20 +0200
Subject: [PATCH] improve includes: only include strictly necessary

---
 ippl/src/AppTypes/Vektor.h                    | 20 +++++---
 ippl/src/FFT/FFT.hpp                          |  2 +-
 ippl/src/Field/BareField.h                    |  1 +
 ippl/src/Field/BareField.hpp                  |  3 +-
 ippl/src/Index/SIndexAssign.hpp               |  6 +--
 ippl/src/Meshes/UniformCartesian.hpp          |  1 -
 ippl/src/Message/Communicate.cpp              |  1 -
 ippl/src/Message/Message.h                    |  1 -
 ippl/src/Message/Message.hpp                  |  1 -
 ippl/src/Particle/AbstractParticle.h          |  4 +-
 ippl/src/Particle/Interpolator.h              |  5 +-
 ippl/src/Particle/IpplParticleBase.h          |  6 ++-
 ippl/src/Particle/PAssignDefs.h               |  3 +-
 ippl/src/Particle/ParticleAttrib.h            |  1 +
 ippl/src/SubParticle/SubParticleAssignDefs.h  |  2 +-
 ippl/src/Utility/DiscField.h                  |  3 --
 ippl/src/Utility/DiscField.hpp                |  1 -
 ippl/src/Utility/DiscParticle.h               |  5 +-
 ippl/src/Utility/Inform.h                     |  1 +
 ippl/src/Utility/IpplInfo.cpp                 |  1 +
 ippl/src/Utility/IpplInfo.h                   |  5 +-
 ippl/src/Utility/IpplMemoryUsage.cpp          |  3 ++
 ippl/src/Utility/IpplMemoryUsage.h            |  6 +--
 ippl/src/Utility/IpplStats.h                  |  3 +-
 ippl/src/Utility/IpplTimings.cpp              |  1 -
 ippl/src/Utility/PAssert.h                    |  1 -
 optimizer/Comm/types.h                        |  2 -
 optimizer/Util/CmdArguments.cpp               |  2 +
 optimizer/Util/CmdArguments.h                 |  1 -
 optimizer/Util/MPIHelper.cpp                  |  1 +
 optimizer/Util/Types.h                        |  9 +---
 src/AbstractObjects/Attribute.cpp             |  2 +
 src/AbstractObjects/Attribute.h               |  3 --
 src/Algorithms/ParallelTTracker.cpp           |  7 ++-
 src/Algorithms/ThickTracker.h                 | 29 +++--------
 src/BasicActions/Option.cpp                   |  6 +--
 src/BasicActions/PSystem.cpp                  |  3 +-
 src/BasicActions/System.cpp                   |  3 +-
 src/Classic/AbsBeamline/BeamStripping.cpp     |  5 +-
 src/Classic/AbsBeamline/Component.h           |  1 -
 src/Classic/AbsBeamline/Degrader.cpp          |  3 +-
 src/Classic/AbsBeamline/Degrader.h            |  2 +
 src/Classic/AbsBeamline/ElementBase.h         |  3 +-
 src/Classic/AbsBeamline/SBend.cpp             |  7 +--
 src/Classic/Algorithms/PBunchDefs.h           | 31 +-----------
 src/Classic/Algorithms/PartBins.h             |  2 -
 src/Classic/Algorithms/PartBunch.cpp          | 22 +++------
 src/Classic/Algorithms/PartBunchBase.h        | 39 ++++++++-------
 src/Classic/Algorithms/PartBunchBase.hpp      | 15 +++---
 src/Classic/Algorithms/PartData.h             |  3 --
 .../Algorithms/PolynomialTimeDependence.cpp   |  2 +
 .../Algorithms/PolynomialTimeDependence.h     |  5 +-
 .../Algorithms/SplineTimeDependence.cpp       |  2 +
 src/Classic/Algorithms/SplineTimeDependence.h |  5 +-
 src/Classic/Algorithms/Vektor.h               |  7 ---
 src/Classic/Beamlines/Beamline.h              |  3 --
 src/Classic/Beamlines/TBeamline.h             |  2 +-
 src/Classic/MemoryManagement/RCObject.h       |  2 -
 src/Classic/Parser/Statement.h                |  2 +-
 src/Classic/Solvers/BeamStrippingPhysics.cpp  |  2 +-
 src/Classic/Solvers/CollimatorPhysics.cpp     |  4 +-
 src/Classic/Solvers/CollimatorPhysics.hh      | 12 ++---
 src/Classic/Structure/LossDataSink.cpp        |  1 -
 src/Classic/Structure/LossDataSink.h          |  8 ++--
 src/Classic/Structure/MeshGenerator.h         | 23 ++++++++-
 src/Classic/Structure/PeakFinder.cpp          |  4 +-
 src/Classic/Structure/PeakFinder.h            |  1 -
 src/Classic/TrimCoils/OpalTrimCoil.cpp        |  2 +-
 src/Classic/TrimCoils/OpalTrimCoil.h          |  1 +
 src/Distribution/ClosedOrbitFinder.h          |  1 -
 src/Distribution/Distribution.cpp             |  1 -
 src/Distribution/SigmaGenerator.h             |  7 ++-
 src/Elements/OpalElement.h                    |  1 +
 src/Main.cpp                                  | 48 ++++++-------------
 src/OpalParser/IfStatement.cpp                |  1 +
 src/OpalParser/OpalParser.cpp                 |  4 +-
 src/OpalParser/WhileStatement.cpp             |  3 ++
 src/Sample/Sampler.cpp                        |  1 +
 src/Sample/Sampler.h                          |  5 +-
 src/Solvers/BoxCornerDomain.h                 |  6 +--
 src/Solvers/FFTBoxPoissonSolver.h             |  5 ++
 src/Solvers/FFTPoissonSolver.h                |  4 ++
 src/Solvers/IrregularDomain.h                 |  5 +-
 src/Solvers/P3MPoissonSolver.h                |  8 +++-
 src/Solvers/PoissonSolver.h                   |  7 +++
 src/Structure/Beam.h                          |  1 +
 src/Structure/DataSink.cpp                    | 12 ++---
 src/Structure/DataSink.h                      | 13 +++--
 src/Structure/H5PartWrapper.h                 | 12 +++--
 src/Structure/H5PartWrapperForPC.cpp          |  2 -
 src/Structure/H5PartWrapperForPC.h            |  3 +-
 src/Structure/H5PartWrapperForPT.cpp          |  3 +-
 src/Structure/H5PartWrapperForPT.h            |  3 --
 src/Structure/IpplInfoWrapper.h               |  2 +-
 src/Structure/SDDSWriter.h                    |  1 -
 src/Track/TrackEnd.h                          |  1 -
 src/opal.cpp                                  |  7 ++-
 src/opal.h                                    |  3 +-
 tests/ippl_src/Index/Index.cpp                |  1 +
 tests/ippl_src/Meshes/Average.cpp             |  1 +
 tests/ippl_src/Meshes/CartesianCentering.cpp  |  4 +-
 tests/ippl_src/Particle/EdgeCentering.cpp     |  5 +-
 102 files changed, 263 insertions(+), 294 deletions(-)

diff --git a/ippl/src/AppTypes/Vektor.h b/ippl/src/AppTypes/Vektor.h
index 7f92412cc..7a7ef5f14 100644
--- a/ippl/src/AppTypes/Vektor.h
+++ b/ippl/src/AppTypes/Vektor.h
@@ -17,6 +17,7 @@
 #include "PETE/IpplExpressions.h"
 #include "AppTypes/TSVMeta.h"
 
+#include <cmath>
 #include <iostream>
 #include <iomanip>
 
@@ -277,6 +278,17 @@ cross(const Vektor<T1,D> &lhs, const Vektor<T2,D> &rhs)
   return TSV_MetaCross< Vektor<T1,D> , Vektor<T2,D> > :: apply(lhs,rhs);
 }
 
+//----------------------------------------------------------------------
+// euclidean norm
+//----------------------------------------------------------------------
+template < class T, unsigned D >
+inline double
+euclidean_norm(const Vektor<T, D> &a)
+{
+  return std::sqrt(dot(a, a));
+}
+
+
 //----------------------------------------------------------------------
 // I/O
 template<class T, unsigned D>
@@ -296,10 +308,4 @@ inline std::ostream& operator<<(std::ostream& out, const Vektor<T,D>& rhs)
   return out;
 }
 
-#endif // VEKTOR_H
-
-/***************************************************************************
- * $RCSfile: Vektor.h,v $   $Author: adelmann $
- * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:24 $
- * IPPL_VERSION_ID: $Id: Vektor.h,v 1.1.1.1 2003/01/23 07:40:24 adelmann Exp $
- ***************************************************************************/
\ No newline at end of file
+#endif // VEKTOR_H
\ No newline at end of file
diff --git a/ippl/src/FFT/FFT.hpp b/ippl/src/FFT/FFT.hpp
index b1a3c6774..91c8e6ff1 100644
--- a/ippl/src/FFT/FFT.hpp
+++ b/ippl/src/FFT/FFT.hpp
@@ -15,7 +15,7 @@
 #include "FFT/FFT.h"
 #include "FieldLayout/FieldLayout.h"
 #include "Field/BareField.h"
-#include "Utility/IpplStats.h"
+//#include "Utility/IpplStats.h"
 
 //=============================================================================
 // FFT CCTransform Constructors
diff --git a/ippl/src/Field/BareField.h b/ippl/src/Field/BareField.h
index 7af317ab2..23e7cff06 100644
--- a/ippl/src/Field/BareField.h
+++ b/ippl/src/Field/BareField.h
@@ -31,6 +31,7 @@
 #include "Index/SIndex.h"
 #include "SubField/SubBareField.h"
 #include "Utility/IpplInfo.h"
+#include "Utility/IpplStats.h"
 #include "Utility/PAssert.h"
 #include "Utility/Unique.h"
 #include "Utility/my_auto_ptr.h"
diff --git a/ippl/src/Field/BareField.hpp b/ippl/src/Field/BareField.hpp
index 0bb7f462d..6b7a8f2ad 100644
--- a/ippl/src/Field/BareField.hpp
+++ b/ippl/src/Field/BareField.hpp
@@ -33,10 +33,9 @@
 #include "Utility/Inform.h"
 #include "Utility/Unique.h"
 #include "Utility/IpplInfo.h"
-#include "Utility/IpplStats.h"
+//#include "Utility/IpplStats.h"
 
 #include <map>
-#include <utility>
 #include <cstdlib>
 
 
diff --git a/ippl/src/Index/SIndexAssign.hpp b/ippl/src/Index/SIndexAssign.hpp
index cb7ce6b66..fab0558d6 100644
--- a/ippl/src/Index/SIndexAssign.hpp
+++ b/ippl/src/Index/SIndexAssign.hpp
@@ -27,9 +27,9 @@
 #include "Index/SIndexAssign.h"
 #include "Index/SIndex.h"
 #include "Field/BrickIterator.h"
-#include "Field/Field.h"
-#include "Field/IndexedField.h"
-#include "Field/Assign.h"
+// #include "Field/Field.h"
+// #include "Field/IndexedField.h"
+// #include "Field/Assign.h"
 #include "Utility/IpplInfo.h"
 
 
diff --git a/ippl/src/Meshes/UniformCartesian.hpp b/ippl/src/Meshes/UniformCartesian.hpp
index c220b1c47..203b15ba5 100644
--- a/ippl/src/Meshes/UniformCartesian.hpp
+++ b/ippl/src/Meshes/UniformCartesian.hpp
@@ -14,7 +14,6 @@
 #include "Field/BareField.h"
 #include "Field/BrickExpression.h"
 #include "Field/LField.h"
-#include "Field/Field.h"
 #include "Field/Assign.h"
 #include "Field/AssignDefs.h"
 
diff --git a/ippl/src/Message/Communicate.cpp b/ippl/src/Message/Communicate.cpp
index 377cc3193..4db98415c 100644
--- a/ippl/src/Message/Communicate.cpp
+++ b/ippl/src/Message/Communicate.cpp
@@ -38,7 +38,6 @@
 
 #include "Utility/IpplInfo.h"
 #include "Utility/IpplStats.h"
-#include "Utility/RandomNumberGen.h"
 #include "Utility/PAssert.h"
 #include <cstdio>
 
diff --git a/ippl/src/Message/Message.h b/ippl/src/Message/Message.h
index 65ca219a1..13499e08e 100644
--- a/ippl/src/Message/Message.h
+++ b/ippl/src/Message/Message.h
@@ -31,7 +31,6 @@
  * of resolving who needs to free up the storage used for the Message elements.
  ***************************************************************************/
 
-#include "Utility/Inform.h"
 #include <complex>
 #include <cstddef>
 #include <vector>
diff --git a/ippl/src/Message/Message.hpp b/ippl/src/Message/Message.hpp
index 67e7b0b31..033c187a6 100644
--- a/ippl/src/Message/Message.hpp
+++ b/ippl/src/Message/Message.hpp
@@ -12,7 +12,6 @@
  ***************************************************************************/
 
 #include "Message/Message.h"
-#include "Utility/Inform.h"
 #include "Utility/IpplInfo.h"
 
 #include <iterator>
diff --git a/ippl/src/Particle/AbstractParticle.h b/ippl/src/Particle/AbstractParticle.h
index 9ba7e8c0e..64e46479f 100644
--- a/ippl/src/Particle/AbstractParticle.h
+++ b/ippl/src/Particle/AbstractParticle.h
@@ -22,7 +22,9 @@
 #define ABSTRACT_PARTICLE_H
 
 #include "Particle/ParticleLayout.h"
-#include "Particle/ParticleAttrib.h"
+
+template<class T> class ParticleAttrib;
+class ParticleAttribBase;
 
 template <class T, unsigned Dim>
 class AbstractParticle {
diff --git a/ippl/src/Particle/Interpolator.h b/ippl/src/Particle/Interpolator.h
index 41142fe01..ee11f7e04 100644
--- a/ippl/src/Particle/Interpolator.h
+++ b/ippl/src/Particle/Interpolator.h
@@ -16,14 +16,13 @@
 #include "Field/LField.h"
 #include "Field/CompressedBrickIterator.h"
 #include "Index/NDIndex.h"
+#include "Meshes/Centering.h"
 #include "AppTypes/Vektor.h"
 #include "Utility/IpplInfo.h"
 #include "Utility/IpplException.h"
 
-#include <iostream>
+#include <ostream>
 #include <vector>
-#include <utility>
-#include <cmath>
 
 // Helper class and functions for finding nearest grid point given centering
 
diff --git a/ippl/src/Particle/IpplParticleBase.h b/ippl/src/Particle/IpplParticleBase.h
index fa5e4a163..bf2b807ad 100644
--- a/ippl/src/Particle/IpplParticleBase.h
+++ b/ippl/src/Particle/IpplParticleBase.h
@@ -95,15 +95,18 @@
 
 // include files
 #include "Particle/AbstractParticle.h"
+#include "Particle/ParticleAttribBase.h"
+#include "Particle/ParticleLayout.h"
 #include "AppTypes/Vektor.h"
 #include "DataSource/DataSource.h"
 #include "DataSource/MakeDataSource.h"
 #include "Message/Formatter.h"
 #include <vector>
-#include <algorithm>  // Include algorithms
 #include <utility>
 #include <iostream>
 
+template <class T, unsigned Dim>
+using PLayout = ParticleLayout<T, Dim>;
 
 // forward declarations
 class Inform;
@@ -120,7 +123,6 @@ template <class T, unsigned D> class ParticleBConds;
 template<class PLayout>
 class IpplParticleBase : public DataSource,
                          public AbstractParticle<typename PLayout::Position_t, PLayout::Dimension> {
-
 public:
     // useful enums
     enum { Dim = PLayout::Dimension };
diff --git a/ippl/src/Particle/PAssignDefs.h b/ippl/src/Particle/PAssignDefs.h
index e70c12669..8304ecb04 100644
--- a/ippl/src/Particle/PAssignDefs.h
+++ b/ippl/src/Particle/PAssignDefs.h
@@ -18,7 +18,8 @@
 // forward declarations
 template<class T> class ParticleAttrib;
 template<class T, unsigned Dim> class ParticleAttribElem;
-
+template<class T> class ParticleAttribIterator;
+template <class T> class ParticleAttribConstIterator;
 
 //////////////////////////////////////////////////////////////////////
 //
diff --git a/ippl/src/Particle/ParticleAttrib.h b/ippl/src/Particle/ParticleAttrib.h
index 3673425b8..f84b63323 100644
--- a/ippl/src/Particle/ParticleAttrib.h
+++ b/ippl/src/Particle/ParticleAttrib.h
@@ -73,6 +73,7 @@
 // include files
 #include "Particle/ParticleAttribBase.h"
 #include "Particle/ParticleAttribElem.h"
+#include "Particle/PAssign.h"
 #include "SubParticle/SubParticleAttrib.h"
 #include "DataSource/DataSource.h"
 #include "DataSource/MakeDataSource.h"
diff --git a/ippl/src/SubParticle/SubParticleAssignDefs.h b/ippl/src/SubParticle/SubParticleAssignDefs.h
index 4535de978..82d40b001 100644
--- a/ippl/src/SubParticle/SubParticleAssignDefs.h
+++ b/ippl/src/SubParticle/SubParticleAssignDefs.h
@@ -13,7 +13,7 @@
 
 // include files
 #include "SubField/SubFieldAssignDefs.h"
-#include "SubParticle/SubParticleAssign.h"
+#include "SubParticle/SubParticleAttrib.h"
 
 //////////////////////////////////////////////////////////////////////
 //
diff --git a/ippl/src/Utility/DiscField.h b/ippl/src/Utility/DiscField.h
index 2cdbb53cd..48b7a336f 100644
--- a/ippl/src/Utility/DiscField.h
+++ b/ippl/src/Utility/DiscField.h
@@ -14,7 +14,6 @@
 // include files
 #include "Index/NDIndex.h"
 #include "Field/BrickExpression.h"
-#include "Field/Field.h"
 #include "Utility/DiscBuffer.h"
 #include "Utility/DiscConfig.h"
 #include "Utility/Inform.h"
@@ -24,8 +23,6 @@
 #include <cstdlib>
 #include <unistd.h>
 #include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
 
 #include <vector>
 #include <iostream>
diff --git a/ippl/src/Utility/DiscField.hpp b/ippl/src/Utility/DiscField.hpp
index 2582eb84e..e6ba34123 100644
--- a/ippl/src/Utility/DiscField.hpp
+++ b/ippl/src/Utility/DiscField.hpp
@@ -27,7 +27,6 @@
 #include "Utility/DiscField.h"
 #include "Utility/DiscConfig.h"
 #include "Utility/DiscMeta.h"
-#include "Field/BrickIterator.h"
 #include "Message/Tags.h"
 
 #include "Utility/PAssert.h"
diff --git a/ippl/src/Utility/DiscParticle.h b/ippl/src/Utility/DiscParticle.h
index 632ec760f..51bfee3db 100644
--- a/ippl/src/Utility/DiscParticle.h
+++ b/ippl/src/Utility/DiscParticle.h
@@ -15,9 +15,9 @@
 #include "Utility/DiscConfig.h"
 #include "Utility/IpplInfo.h"
 #include "Utility/PAssert.h"
+#include "Message/Communicate.h"
 #include "Message/Message.h"
-
-
+#include "Message/Tags.h"
 
 #include <vector>
 #include <iostream>
@@ -26,7 +26,6 @@
 // forward declarations
 template<class T> class IpplParticleBase;
 template<class T> class ParticleAttrib;
-class Message;
 
 class DiscParticle {
 
diff --git a/ippl/src/Utility/Inform.h b/ippl/src/Utility/Inform.h
index 3317301d4..21c9f86d2 100644
--- a/ippl/src/Utility/Inform.h
+++ b/ippl/src/Utility/Inform.h
@@ -34,6 +34,7 @@
 #include <iostream>
 #include <iomanip>
 #include <sstream>
+#include <string>
 
 #define INFORM_ALL_NODES        (-1)
 
diff --git a/ippl/src/Utility/IpplInfo.cpp b/ippl/src/Utility/IpplInfo.cpp
index a626255a5..113bd1198 100644
--- a/ippl/src/Utility/IpplInfo.cpp
+++ b/ippl/src/Utility/IpplInfo.cpp
@@ -25,6 +25,7 @@
 
 // include files
 #include "Utility/IpplInfo.h"
+#include "Utility/Inform.h"
 #include "Utility/IpplStats.h"
 #include "Utility/PAssert.h"
 #include "Utility/RandomNumberGen.h"
diff --git a/ippl/src/Utility/IpplInfo.h b/ippl/src/Utility/IpplInfo.h
index ce1fe8211..0355229ce 100644
--- a/ippl/src/Utility/IpplInfo.h
+++ b/ippl/src/Utility/IpplInfo.h
@@ -43,9 +43,8 @@
  */
 
 // include files
-#include "Utility/Inform.h"
-#include "Message/Communicate.h"
 #include "Utility/StaticIpplInfo.h"
+#include "Utility/Inform.h"
 
 #include <iostream>
 #include <stack>
@@ -56,6 +55,8 @@
 #include <mpi.h>
 
 // forward declarations
+class Communicate;
+class Inform;
 class IpplStats;
 class IpplInfo;
 std::ostream& operator<<(std::ostream&, const IpplInfo&);
diff --git a/ippl/src/Utility/IpplMemoryUsage.cpp b/ippl/src/Utility/IpplMemoryUsage.cpp
index 2e2ca97e6..b5bfbedc8 100644
--- a/ippl/src/Utility/IpplMemoryUsage.cpp
+++ b/ippl/src/Utility/IpplMemoryUsage.cpp
@@ -40,6 +40,9 @@
 //
 #include "Utility/IpplMemoryUsage.h"
 
+#include "Message/GlobalComm.h"
+#include "Utility/IpplInfo.h"
+
 //////////////////////////////////////////////////////////////////////
 IpplMemoryUsage::IpplMemoryUsage()
 { }
diff --git a/ippl/src/Utility/IpplMemoryUsage.h b/ippl/src/Utility/IpplMemoryUsage.h
index bcb43a779..094915ab8 100644
--- a/ippl/src/Utility/IpplMemoryUsage.h
+++ b/ippl/src/Utility/IpplMemoryUsage.h
@@ -38,11 +38,11 @@
 // You should have received a copy of the GNU General Public License
 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
 //
-#ifndef IPPL_MEMPRYUSAGE_H
-#define IPPL_MEMPRYUSAGE_H
+#ifndef IPPL_MEMORYUSAGE_H
+#define IPPL_MEMORYUSAGE_H
 
-#include "Ippl.h"
 #include <memory>
+#include <string>
 
 #include <sys/resource.h>
 #include <sys/time.h> // not required but increases portability
diff --git a/ippl/src/Utility/IpplStats.h b/ippl/src/Utility/IpplStats.h
index a7be10ac3..b22678d39 100644
--- a/ippl/src/Utility/IpplStats.h
+++ b/ippl/src/Utility/IpplStats.h
@@ -38,10 +38,11 @@
 // include files
 #include "Utility/IpplInfo.h"
 #include "Utility/Timer.h"
-#include "Utility/Inform.h"
 
 #include <vector>
 
+class Inform;
+
 class IpplStats {
 
 public:
diff --git a/ippl/src/Utility/IpplTimings.cpp b/ippl/src/Utility/IpplTimings.cpp
index 427c52cf6..884407a6a 100644
--- a/ippl/src/Utility/IpplTimings.cpp
+++ b/ippl/src/Utility/IpplTimings.cpp
@@ -7,7 +7,6 @@
 
 #include "Utility/IpplTimings.h"
 #include "Utility/Inform.h"
-#include "Utility/IpplInfo.h"
 #include "Message/GlobalComm.h"
 #include "PETE/IpplExpressions.h"
 
diff --git a/ippl/src/Utility/PAssert.h b/ippl/src/Utility/PAssert.h
index a780daef3..4659fa032 100644
--- a/ippl/src/Utility/PAssert.h
+++ b/ippl/src/Utility/PAssert.h
@@ -6,7 +6,6 @@
 
 #ifndef PASSERT_H
 #define PASSERT_H
-#include "Utility/IpplInfo.h"
 
 #include <exception>
 #include <stdexcept>
diff --git a/optimizer/Comm/types.h b/optimizer/Comm/types.h
index 259fb38f3..ecd0a4a3c 100644
--- a/optimizer/Comm/types.h
+++ b/optimizer/Comm/types.h
@@ -21,8 +21,6 @@
 #ifndef __COMM_TYPES__
 #define __COMM_TYPES__
 
-#include <vector>
-
 #include "mpi.h"
 
 namespace Comm {
diff --git a/optimizer/Util/CmdArguments.cpp b/optimizer/Util/CmdArguments.cpp
index f247e5640..038fdebd3 100644
--- a/optimizer/Util/CmdArguments.cpp
+++ b/optimizer/Util/CmdArguments.cpp
@@ -27,6 +27,8 @@
 //
 #include "Util/CmdArguments.h"
 
+#include "boost/algorithm/string.hpp"
+
 void CmdArguments::addArguments(int argc, char **argv) {
 
     for(int i=1; i<argc; i++) {
diff --git a/optimizer/Util/CmdArguments.h b/optimizer/Util/CmdArguments.h
index bff896739..2f079944e 100644
--- a/optimizer/Util/CmdArguments.h
+++ b/optimizer/Util/CmdArguments.h
@@ -35,7 +35,6 @@
 #include <set>
 
 #include "boost/smart_ptr.hpp"
-#include "boost/algorithm/string.hpp"
 #include "boost/utility/value_init.hpp"
 
 #include "Util/OptPilotException.h"
diff --git a/optimizer/Util/MPIHelper.cpp b/optimizer/Util/MPIHelper.cpp
index be0129382..d3ebc3954 100644
--- a/optimizer/Util/MPIHelper.cpp
+++ b/optimizer/Util/MPIHelper.cpp
@@ -22,6 +22,7 @@
 
 #include <boost/static_assert.hpp>
 #include <boost/serialization/map.hpp>
+#include <boost/serialization/vector.hpp>
 
 #include <boost/archive/text_oarchive.hpp>
 #include <boost/archive/text_iarchive.hpp>
diff --git a/optimizer/Util/Types.h b/optimizer/Util/Types.h
index cff85c900..3d32e0704 100644
--- a/optimizer/Util/Types.h
+++ b/optimizer/Util/Types.h
@@ -21,17 +21,12 @@
 #ifndef __TYPES_H__
 #define __TYPES_H__
 
-#include <vector>
 #include <map>
+#include <utility>
+#include <vector>
 
-#include <boost/serialization/map.hpp>
-#include "boost/serialization/vector.hpp"
 #include "boost/tuple/tuple.hpp"
 
-#include "boost/variant.hpp"
-#include "boost/fusion/adapted/struct/adapt_struct.hpp"
-#include "boost/fusion/include/adapt_struct.hpp"
-
 #include "Expression/Expression.h"
 
 //FIXME: add namespaces
diff --git a/src/AbstractObjects/Attribute.cpp b/src/AbstractObjects/Attribute.cpp
index 9ad9e8991..d7285595a 100644
--- a/src/AbstractObjects/Attribute.cpp
+++ b/src/AbstractObjects/Attribute.cpp
@@ -20,6 +20,8 @@
 #include "AbstractObjects/AttributeBase.h"
 #include "Utilities/Options.h"
 
+#include "Utility/Inform.h"
+
 #include <set>
 #include <iostream>
 
diff --git a/src/AbstractObjects/Attribute.h b/src/AbstractObjects/Attribute.h
index 344981055..77907f8cc 100644
--- a/src/AbstractObjects/Attribute.h
+++ b/src/AbstractObjects/Attribute.h
@@ -24,9 +24,6 @@
 #include <iosfwd>
 #include <string>
 
-// #include <Ippl.h>
-#include <Utility/Inform.h>
-
 class Statement;
 
 // Class Attribute
diff --git a/src/Algorithms/ParallelTTracker.cpp b/src/Algorithms/ParallelTTracker.cpp
index 73c32bcd8..868cb338f 100644
--- a/src/Algorithms/ParallelTTracker.cpp
+++ b/src/Algorithms/ParallelTTracker.cpp
@@ -22,19 +22,18 @@
 #include "Algorithms/ParallelTTracker.h"
 
 #include <cfloat>
-#include <iostream>
+#include <cmath>
 #include <fstream>
+#include <limits>
 #include <iomanip>
+#include <iostream>
 #include <sstream>
 #include <string>
-#include <limits>
-#include <cmath>
 
 #include "Algorithms/OrbitThreader.h"
 #include "Algorithms/CavityAutophaser.h"
 #include "Beamlines/Beamline.h"
 #include "Beamlines/FlaggedBeamline.h"
-#include "Lines/Sequence.h"
 
 #include "Solvers/CSRWakeFunction.hh"
 
diff --git a/src/Algorithms/ThickTracker.h b/src/Algorithms/ThickTracker.h
index 7ea954f78..175731ac5 100644
--- a/src/Algorithms/ThickTracker.h
+++ b/src/Algorithms/ThickTracker.h
@@ -24,42 +24,27 @@
 #define OPAL_ThickTracker_HH
 
 #include "Algorithms/Tracker.h"
-#include "Structure/DataSink.h"
 
 #include "Hamiltonian.h"
 
-#include "MapAnalyser.h"
-
 #include "Algorithms/IndexMap.h"
 #include "AbsBeamline/BeamStripping.h"
-#include "AbsBeamline/CCollimator.h"
-#include "AbsBeamline/Corrector.h"
-#include "AbsBeamline/Degrader.h"
 #include "AbsBeamline/Drift.h"
-#include "AbsBeamline/FlexibleCollimator.h"
 #include "AbsBeamline/ElementBase.h"
-#include "AbsBeamline/Marker.h"
-#include "AbsBeamline/Monitor.h"
 #include "AbsBeamline/Multipole.h"
-#include "AbsBeamline/Probe.h"
-#include "AbsBeamline/RFCavity.h"
-#include "AbsBeamline/RBend.h"
 #include "AbsBeamline/RBend3D.h"
 #include "AbsBeamline/SBend.h"
-#include "AbsBeamline/Septum.h"
-#include "AbsBeamline/Solenoid.h"
-#include "AbsBeamline/TravelingWave.h"
 
 #include "Elements/OpalBeamline.h"
 
-#include "Structure/Beam.h"
-
-//#include <array>
 #include <cmath>
-
+#include <list>
+#include <string>
 #include <tuple>
+#include <vector>
 
 class BMultipoleField;
+class DataSink;
 
 template <class T, unsigned Dim>
 class PartBunchBase;
@@ -101,14 +86,13 @@ class PartBunchBase;
 
 class ThickTracker: public Tracker {
 
-public:
+private:
     typedef Hamiltonian::series_t                       series_t;
-    typedef MapAnalyser::fMatrix_t                      fMatrix_t;
-    typedef MapAnalyser::cfMatrix_t                     cfMatrix_t;
     typedef FVps<double, 6>                             map_t;
     typedef FVector<double, 6>                          particle_t;
     typedef std::tuple<series_t, std::size_t, double>   tuple_t;
     typedef std::list<tuple_t>                          beamline_t;
+    typedef FMatrix<double, 6, 6>                       fMatrix_t;
 
 public:
 
@@ -331,7 +315,6 @@ private:
 
 
     Hamiltonian hamiltonian_m;
-    MapAnalyser mapAnalyser_m;
 
 
     Vector_t RefPartR_m;
diff --git a/src/BasicActions/Option.cpp b/src/BasicActions/Option.cpp
index bb80d744a..1c8f2c158 100644
--- a/src/BasicActions/Option.cpp
+++ b/src/BasicActions/Option.cpp
@@ -20,13 +20,13 @@
 #include "BasicActions/Option.h"
 #include "Attributes/Attributes.h"
 #include "Parser/FileStream.h"
+#include "Utilities/OpalException.h"
 #include "Utilities/Options.h"
 #include "Utilities/OptionTypes.h"
 #include "Utilities/ClassicRandom.h"
-#include "Utility/IpplInfo.h"
-
-#include "Utilities/OpalException.h"
 
+#include "Utility/Inform.h"
+#include "Utility/IpplInfo.h"
 #include "Utility/IpplMemoryUsage.h"
 
 #include <ctime>
diff --git a/src/BasicActions/PSystem.cpp b/src/BasicActions/PSystem.cpp
index a8c34ed5b..d3698e7fc 100644
--- a/src/BasicActions/PSystem.cpp
+++ b/src/BasicActions/PSystem.cpp
@@ -18,9 +18,10 @@
 
 #include "BasicActions/PSystem.h"
 
-#include "Ippl.h"
 #include "Attributes/Attributes.h"
 
+#include "Utility/IpplInfo.h"
+
 #include <cstdlib>
 // Class PSystem
 // ------------------------------------------------------------------------
diff --git a/src/BasicActions/System.cpp b/src/BasicActions/System.cpp
index 6a78bd47c..7c3b614d5 100644
--- a/src/BasicActions/System.cpp
+++ b/src/BasicActions/System.cpp
@@ -18,9 +18,10 @@
 
 #include "BasicActions/System.h"
 
-#include "Ippl.h"
 #include "Attributes/Attributes.h"
 
+#include "Utility/IpplInfo.h"
+
 #include <cstdlib>
 // Class System
 // ------------------------------------------------------------------------
diff --git a/src/Classic/AbsBeamline/BeamStripping.cpp b/src/Classic/AbsBeamline/BeamStripping.cpp
index a456fdb4d..90f384fe9 100644
--- a/src/Classic/AbsBeamline/BeamStripping.cpp
+++ b/src/Classic/AbsBeamline/BeamStripping.cpp
@@ -38,10 +38,7 @@
 #include <cmath>
 #include <cstdio>
 
-#include "Ippl.h"
-
-#include "gsl/gsl_spline.h"
-#include "gsl/gsl_interp.h"
+#include "Utility/Inform.h"
 
 #define CHECK_BSTP_FSCANF_EOF(arg) if (arg == EOF)\
 throw GeneralClassicException("BeamStripping::getPressureFromFile",\
diff --git a/src/Classic/AbsBeamline/Component.h b/src/Classic/AbsBeamline/Component.h
index 8f9f5fa13..51c92da2f 100644
--- a/src/Classic/AbsBeamline/Component.h
+++ b/src/Classic/AbsBeamline/Component.h
@@ -25,7 +25,6 @@
 
 #include "AbsBeamline/ElementBase.h"
 #include "Fields/EMField.h"
-#include "Algorithms/Vektor.h"
 
 class PartData;
 
diff --git a/src/Classic/AbsBeamline/Degrader.cpp b/src/Classic/AbsBeamline/Degrader.cpp
index df2c02cc1..f9f8bcc20 100644
--- a/src/Classic/AbsBeamline/Degrader.cpp
+++ b/src/Classic/AbsBeamline/Degrader.cpp
@@ -21,13 +21,12 @@
 #include "AbsBeamline/Degrader.h"
 #include "Algorithms/PartBunchBase.h"
 #include "AbsBeamline/BeamlineVisitor.h"
-#include "Fields/Fieldmap.h"
 #include "Structure/LossDataSink.h"
 #include "Utilities/Options.h"
 #include "Solvers/ParticleMatterInteractionHandler.hh"
 #include "Physics/Physics.h"
-#include "Utilities/Util.h"
 #include <memory>
+#include <string>
 
 extern Inform *gmsg;
 
diff --git a/src/Classic/AbsBeamline/Degrader.h b/src/Classic/AbsBeamline/Degrader.h
index 239c1ea91..7426f5c43 100644
--- a/src/Classic/AbsBeamline/Degrader.h
+++ b/src/Classic/AbsBeamline/Degrader.h
@@ -25,6 +25,8 @@
 #include "AbsBeamline/Component.h"
 #include "AbsBeamline/BeamlineVisitor.h"
 #include "BeamlineGeometry/StraightGeometry.h"
+
+#include <string>
 #include <vector>
 
 class LossDataSink;
diff --git a/src/Classic/AbsBeamline/ElementBase.h b/src/Classic/AbsBeamline/ElementBase.h
index 7121877da..87f5d6e8e 100644
--- a/src/Classic/AbsBeamline/ElementBase.h
+++ b/src/Classic/AbsBeamline/ElementBase.h
@@ -65,8 +65,8 @@
 
 #include "AbsBeamline/AttributeSet.h"
 #include "BeamlineGeometry/Geometry.h"
+#include "BeamlineGeometry/Euclid3D.h"
 #include "MemoryManagement/RCObject.h"
-#include "Algorithms/Vektor.h"
 #include "Algorithms/Quaternion.h"
 #include "Algorithms/CoordinateSystemTrafo.h"
 #include "Utilities/GeneralClassicException.h"
@@ -328,7 +328,6 @@ public:
 
     virtual bool isInside(const Vector_t &r) const;
 
-    void setMisalignment(double x, double y, double s);
     void setMisalignment(const CoordinateSystemTrafo &cst);
 
     void getMisalignment(double &x, double &y, double &s) const;
diff --git a/src/Classic/AbsBeamline/SBend.cpp b/src/Classic/AbsBeamline/SBend.cpp
index 6c89c6708..15fe1b912 100644
--- a/src/Classic/AbsBeamline/SBend.cpp
+++ b/src/Classic/AbsBeamline/SBend.cpp
@@ -19,13 +19,10 @@
 // ------------------------------------------------------------------------
 
 #include "AbsBeamline/SBend.h"
-#include "Algorithms/PartBunchBase.h"
 #include "AbsBeamline/BeamlineVisitor.h"
-#include "Utilities/Options.h"
 #include "Fields/Fieldmap.h"
-#include "AbstractObjects/OpalData.h"
-#include <iostream>
-#include <fstream>
+
+#include <string>
 
 extern Inform *gmsg;
 
diff --git a/src/Classic/Algorithms/PBunchDefs.h b/src/Classic/Algorithms/PBunchDefs.h
index 9071c7046..89fed8cd0 100644
--- a/src/Classic/Algorithms/PBunchDefs.h
+++ b/src/Classic/Algorithms/PBunchDefs.h
@@ -3,17 +3,10 @@
 
 #include "Algorithms/Vektor.h"
 #include "Particle/IntCIC.h"
-#include "Particle/IntNGP.h"
-#include "Particle/IntSUDS.h"
-#include "Particle/IntTSC.h"
 #include "Particle/ParticleSpatialLayout.h"
-#include "Particle/ParticleUniformLayout.h"
-#include "Particle/ParticleAttrib.h"
 #include "Meshes/UniformCartesian.h"
-#include "Meshes/Centering.h"
 #include "FieldLayout/CenteredFieldLayout.h"
 #include "Field/Field.h"
-#include "FFT/FFT.h"
 
 #ifdef ENABLE_AMR
     #include "Amr/AmrDefs.h"
@@ -22,37 +15,21 @@
 #endif
 
 typedef IntCIC  IntrplCIC_t;
-typedef IntNGP  IntrplNGP_t;
-typedef IntSUDS IntrplSUDS_t;
-typedef IntTSC  IntrplTSC_t;
 
 typedef ParticleSpatialLayout<double, 3>::ParticlePos_t Ppos_t;
 typedef ParticleSpatialLayout<double, 3>::ParticleIndex_t PID_t;
 
-typedef ParticleUniformLayout<double, 3>::ParticlePos_t UPpos_t;
-typedef ParticleUniformLayout<double, 3>::ParticleIndex_t UPID_t;
-
-typedef ParticleAttrib<double> Pscalar_t;
-
-typedef InterpolatorTraits<double, 3, IntrplCIC_t>::Cache_t Pcache_t;
-
 typedef UniformCartesian<3, double> Mesh_t;
 
 typedef ParticleSpatialLayout< double, 3, Mesh_t  > Layout_t;
-typedef ParticleUniformLayout< double, 3  > ULayout_t;
 
 typedef Cell Center_t;
 
 typedef CenteredFieldLayout<3, Mesh_t, Center_t> FieldLayout_t;
+
 typedef Field<double, 3, Mesh_t, Center_t>       Field_t;
 typedef Field<Vector_t, 3, Mesh_t, Center_t>     VField_t;
 
-typedef Field<int, 3, Mesh_t, Center_t>          IField_t;
-typedef Field<std::complex<double>, 3, Mesh_t, Center_t>     CxField_t;
-typedef FFT<RCTransform, 3, double>              FFT_t;
-typedef FFT<SineTransform, 3, double>            SINE_t;
-typedef FFT<CCTransform, 3, double>              FFTC_t;
-
 #ifdef ENABLE_AMR
     typedef amr::AmrField_t                      AmrField_t;
     typedef amr::AmrScalarFieldContainer_t       AmrScalarFieldContainer_t;
@@ -61,10 +38,4 @@ typedef FFT<CCTransform, 3, double>              FFTC_t;
     typedef BoxLibParticle<AmrLayout_t>          AmrParticle_t;
 #endif
 
-namespace ParticleType {
-    enum type { REGULAR,
-                SECONDARY,
-                STRIPPED};
-}
-
 #endif
\ No newline at end of file
diff --git a/src/Classic/Algorithms/PartBins.h b/src/Classic/Algorithms/PartBins.h
index 7d77d8941..4e11711a0 100644
--- a/src/Classic/Algorithms/PartBins.h
+++ b/src/Classic/Algorithms/PartBins.h
@@ -25,8 +25,6 @@
 #include <memory>
 #include <vector>
 
-#include "Algorithms/PBunchDefs.h"
-
 class Inform;
 
 class PartBins {
diff --git a/src/Classic/Algorithms/PartBunch.cpp b/src/Classic/Algorithms/PartBunch.cpp
index d7f7c9154..767369953 100644
--- a/src/Classic/Algorithms/PartBunch.cpp
+++ b/src/Classic/Algorithms/PartBunch.cpp
@@ -17,32 +17,24 @@
 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
 //
 #include "Algorithms/PartBunch.h"
-#include "FixedAlgebra/FMatrix.h"
-#include "FixedAlgebra/FVector.h"
+
 #include <cfloat>
 #include <memory>
 #include <utility>
 
-
-#include "Distribution/Distribution.h"  // OPAL file
-#include "Structure/FieldSolver.h"      // OPAL file
-#include "Utilities/GeneralClassicException.h"
+#include "FixedAlgebra/FMatrix.h"
+#include "FixedAlgebra/FVector.h"
+#include "Particle/ParticleBalancer.h"
 
 #include "Algorithms/ListElem.h"
-
-#include <gsl/gsl_rng.h>
-#include <gsl/gsl_histogram.h>
-#include <gsl/gsl_cdf.h>
-#include <gsl/gsl_randist.h>
-#include <gsl/gsl_sf_erf.h>
-#include <gsl/gsl_qrng.h>
+#include "Distribution/Distribution.h"
+#include "Structure/FieldSolver.h"
+#include "Utilities/GeneralClassicException.h"
 
 #ifdef DBG_SCALARFIELD
     #include "Structure/FieldWriter.h"
 #endif
 
-
-
 //#define FIELDSTDOUT
 
 PartBunch::PartBunch(const PartData *ref): // Layout is set using setSolver()
diff --git a/src/Classic/Algorithms/PartBunchBase.h b/src/Classic/Algorithms/PartBunchBase.h
index 47b865bd6..be9af282f 100644
--- a/src/Classic/Algorithms/PartBunchBase.h
+++ b/src/Classic/Algorithms/PartBunchBase.h
@@ -18,29 +18,36 @@
 #ifndef PART_BUNCH_BASE_H
 #define PART_BUNCH_BASE_H
 
-#include "Ippl.h"
-#include "Particle/AbstractParticle.h" //TODO should be in Ippl.h
-#include "Algorithms/PBunchDefs.h"
-#include "Algorithms/OpalParticle.h"
+#include "Utility/IpplTimings.h"
+#include "Particle/AbstractParticle.h"
+#include "Particle/ParticleAttrib.h"
+
 #include "Algorithms/CoordinateSystemTrafo.h"
+#include "Algorithms/OpalParticle.h"
+#include "Algorithms/PBunchDefs.h"
+#include "Algorithms/Quaternion.h"
+#include "Algorithms/Vektor.h"
+
 #include "FixedAlgebra/FMatrix.h"
 #include "FixedAlgebra/FVector.h"
-#include "Algorithms/PartBins.h"
-#include "Algorithms/PartBinsCyc.h"
-#include "Algorithms/PartData.h"
-#include "Algorithms/Quaternion.h"
 
 #include <memory>
 #include <utility>
 #include <vector>
 
-#include "Structure/FieldSolver.h"
-#include "Algorithms/ListElem.h"
-
 class Distribution;
-
-template <class T, int, int> class FMatrix;
-template <class T, int> class FVector;
+class FieldSolver;
+class PartBins;
+class PartBinsCyc;
+class PartData;
+
+namespace ParticleType {
+    enum type { REGULAR,
+                FIELDEMISSION,
+                SECONDARY,
+                NEWSECONDARY,
+                STRIPPED};
+}
 
 template <class T, unsigned Dim>
 class PartBunchBase
@@ -59,8 +66,6 @@ public:
 
 public:
 
-    explicit PartBunchBase(AbstractParticle<T, Dim>* pb);
-
     virtual ~PartBunchBase() { }
 
     PartBunchBase(AbstractParticle<T, Dim>* pb, const PartData *ref);
@@ -629,7 +634,7 @@ protected:
     int distDump_m;
 
     /// Mesh enlargement
-    double dh_m; /// in % how much the mesh is enlarged
+    double dh_m; /// relative enlargement of the mesh
 
     /// if larger than 0, emitt particles for tEmission_m [s]
     double tEmission_m;
diff --git a/src/Classic/Algorithms/PartBunchBase.hpp b/src/Classic/Algorithms/PartBunchBase.hpp
index a99a1232c..4559a3d35 100644
--- a/src/Classic/Algorithms/PartBunchBase.hpp
+++ b/src/Classic/Algorithms/PartBunchBase.hpp
@@ -24,7 +24,11 @@
 #include "Distribution/Distribution.h"
 
 #include "AbstractObjects/OpalData.h"   // OPAL file
+#include "Algorithms/PartBins.h"
+#include "Algorithms/PartBinsCyc.h"
+#include "Algorithms/PartData.h"
 #include "Physics/Physics.h"
+#include "Structure/FieldSolver.h"
 #include "Utilities/GeneralClassicException.h"
 #include "Utilities/OpalException.h"
 #include "Utilities/Options.h"
@@ -34,7 +38,7 @@
 extern Inform *gmsg;
 
 template <class T, unsigned Dim>
-PartBunchBase<T, Dim>::PartBunchBase(AbstractParticle<T, Dim>* pb)
+PartBunchBase<T, Dim>::PartBunchBase(AbstractParticle<T, Dim>* pb, const PartData *ref)
     : R(*(pb->R_p)),
       ID(*(pb->ID_p)),
       pbin_m(nullptr),
@@ -42,7 +46,7 @@ PartBunchBase<T, Dim>::PartBunchBase(AbstractParticle<T, Dim>* pb)
       pmsg_m(nullptr),
       f_stream(nullptr),
       fixed_grid(false),
-//       reference(ref), //FIXME
+      reference(ref),
       unit_state_(units),
       stateOfLastBoundP_(unitless),
       moments_m(),
@@ -93,13 +97,6 @@ PartBunchBase<T, Dim>::PartBunchBase(AbstractParticle<T, Dim>* pb)
     setup(pb);
 }
 
-template <class T, unsigned Dim>
-PartBunchBase<T, Dim>::PartBunchBase(AbstractParticle<T, Dim>* pb, const PartData *ref)
-    : PartBunchBase(pb)
-{
-    reference = ref;
-}
-
 /*
  * Bunch common member functions
  */
diff --git a/src/Classic/Algorithms/PartData.h b/src/Classic/Algorithms/PartData.h
index 735d54416..73636d2a3 100644
--- a/src/Classic/Algorithms/PartData.h
+++ b/src/Classic/Algorithms/PartData.h
@@ -19,9 +19,6 @@
 //
 // ------------------------------------------------------------------------
 
-class LogicalError;
-
-
 // Class PartData
 // ------------------------------------------------------------------------
 /// Particle reference data.
diff --git a/src/Classic/Algorithms/PolynomialTimeDependence.cpp b/src/Classic/Algorithms/PolynomialTimeDependence.cpp
index 00a07a7bf..6827726d7 100644
--- a/src/Classic/Algorithms/PolynomialTimeDependence.cpp
+++ b/src/Classic/Algorithms/PolynomialTimeDependence.cpp
@@ -27,6 +27,8 @@
 
 #include "Algorithms/PolynomialTimeDependence.h"
 
+#include "Utility/Inform.h"
+
 Inform &PolynomialTimeDependence::print(Inform &os) {
   Inform::FmtFlags_t ff = os.flags();
   os << std::scientific;
diff --git a/src/Classic/Algorithms/PolynomialTimeDependence.h b/src/Classic/Algorithms/PolynomialTimeDependence.h
index ac2e7abaa..300f1ad65 100644
--- a/src/Classic/Algorithms/PolynomialTimeDependence.h
+++ b/src/Classic/Algorithms/PolynomialTimeDependence.h
@@ -30,9 +30,9 @@
 
 #include <vector>
 #include <iostream>
-#include "Ippl.h"
 #include "Algorithms/AbstractTimeDependence.h"
 
+class Inform;
 
 /** @class PolynomialTimeDependence
  * 
@@ -91,5 +91,4 @@ Inform &operator<<(Inform &os, PolynomialTimeDependence &p) {
   return p.print(os);
 }
 
-#endif
-
+#endif
\ No newline at end of file
diff --git a/src/Classic/Algorithms/SplineTimeDependence.cpp b/src/Classic/Algorithms/SplineTimeDependence.cpp
index 40d9c3515..6ea5ff6e0 100644
--- a/src/Classic/Algorithms/SplineTimeDependence.cpp
+++ b/src/Classic/Algorithms/SplineTimeDependence.cpp
@@ -31,6 +31,8 @@
 #include "Utilities/GeneralClassicException.h"
 #include "Algorithms/SplineTimeDependence.h"
 
+#include "Utility/Inform.h"
+
 SplineTimeDependence::SplineTimeDependence(size_t splineOrder,
                                            std::vector<double> times,
                                            std::vector<double> values)
diff --git a/src/Classic/Algorithms/SplineTimeDependence.h b/src/Classic/Algorithms/SplineTimeDependence.h
index ede981913..47e004160 100644
--- a/src/Classic/Algorithms/SplineTimeDependence.h
+++ b/src/Classic/Algorithms/SplineTimeDependence.h
@@ -28,14 +28,15 @@
 #ifndef _CLASSIC_SRC_ALGORITHMS_SPLINETIMEDEPENDENCE_H_
 #define _CLASSIC_SRC_ALGORITHMS_SPLINETIMEDEPENDENCE_H_
 
-#include <memory>
+#include <vector>
 
 #include <gsl/gsl_spline.h>
 
-#include "Ippl.h"
 #include "Utilities/GeneralClassicException.h"
 #include "Algorithms/AbstractTimeDependence.h"
 
+class Inform;
+
 /** @class SplineTimeDependence
  * 
  *  Time dependence that follows a spline. Interpolation is supported at 
diff --git a/src/Classic/Algorithms/Vektor.h b/src/Classic/Algorithms/Vektor.h
index 7e974849a..84ffdb3a7 100644
--- a/src/Classic/Algorithms/Vektor.h
+++ b/src/Classic/Algorithms/Vektor.h
@@ -5,11 +5,4 @@
 
 typedef Vektor<double, 3> Vector_t;
 
-/// comment: this should go to AppTypes/Vektor.h
-
-inline
-double euclidean_norm(Vector_t a) {
-    return std::sqrt(dot(a,a));
-}
-
 #endif
\ No newline at end of file
diff --git a/src/Classic/Beamlines/Beamline.h b/src/Classic/Beamlines/Beamline.h
index 80e4e8d72..075988259 100644
--- a/src/Classic/Beamlines/Beamline.h
+++ b/src/Classic/Beamlines/Beamline.h
@@ -24,9 +24,6 @@
 #include "Algorithms/Vektor.h"
 #include "Algorithms/Quaternion.h"
 
-class CLRangeError;
-
-
 // Class Beamline
 // ------------------------------------------------------------------------
 /// An abstract sequence of beam line components.
diff --git a/src/Classic/Beamlines/TBeamline.h b/src/Classic/Beamlines/TBeamline.h
index 2e20b6522..7b9a88182 100644
--- a/src/Classic/Beamlines/TBeamline.h
+++ b/src/Classic/Beamlines/TBeamline.h
@@ -23,10 +23,10 @@
 #include "Beamlines/Beamline.h"
 #include "AbsBeamline/BeamlineVisitor.h"
 #include "Beamlines/BeamlineGeometry.h"
-#include "Utilities/CLRangeError.h"
 #include "Algorithms/Vektor.h"
 #include "Algorithms/Quaternion.h"
 #include <algorithm>
+#include <string>
 #include <list>
 
 template <class T>
diff --git a/src/Classic/MemoryManagement/RCObject.h b/src/Classic/MemoryManagement/RCObject.h
index 2260ce7d6..679d77026 100644
--- a/src/Classic/MemoryManagement/RCObject.h
+++ b/src/Classic/MemoryManagement/RCObject.h
@@ -36,8 +36,6 @@
 //  All constructors, the destructor, and the assignment operators are
 //  protected, since a stand-alone RCObject makes no sense.
 
-//#include <Ippl.h>
-
 
 class RCObject {
 
diff --git a/src/Classic/Parser/Statement.h b/src/Classic/Parser/Statement.h
index da2d3b9e0..3c13c0187 100644
--- a/src/Classic/Parser/Statement.h
+++ b/src/Classic/Parser/Statement.h
@@ -25,7 +25,7 @@
 #include <list>
 #include <string>
 
-#include <Ippl.h>
+#include "Utility/Inform.h"
 
 class Parser;
 
diff --git a/src/Classic/Solvers/BeamStrippingPhysics.cpp b/src/Classic/Solvers/BeamStrippingPhysics.cpp
index f94dce5be..823207a13 100644
--- a/src/Classic/Solvers/BeamStrippingPhysics.cpp
+++ b/src/Classic/Solvers/BeamStrippingPhysics.cpp
@@ -31,7 +31,7 @@
 #include "Structure/LossDataSink.h"
 #include "Utilities/Options.h"
 
-#include "Ippl.h"
+#include "Utility/Inform.h"
 
 #include <iostream>
 #include <fstream>
diff --git a/src/Classic/Solvers/CollimatorPhysics.cpp b/src/Classic/Solvers/CollimatorPhysics.cpp
index 11e529447..8c5812a5e 100644
--- a/src/Classic/Solvers/CollimatorPhysics.cpp
+++ b/src/Classic/Solvers/CollimatorPhysics.cpp
@@ -35,7 +35,7 @@
 #include "Utilities/Util.h"
 #include "Utilities/Timer.h"
 
-#include "Ippl.h"
+#include "Utility/Inform.h"
 
 #include <gsl/gsl_randist.h>
 
@@ -44,6 +44,8 @@
 #include <fstream>
 #include <algorithm>
 
+#include <sys/time.h>
+
 namespace {
     struct DegraderInsideTester: public InsideTester {
         explicit DegraderInsideTester(ElementBase * el) {
diff --git a/src/Classic/Solvers/CollimatorPhysics.hh b/src/Classic/Solvers/CollimatorPhysics.hh
index fc8fc6bfa..d0690b628 100644
--- a/src/Classic/Solvers/CollimatorPhysics.hh
+++ b/src/Classic/Solvers/CollimatorPhysics.hh
@@ -21,18 +21,18 @@
 #ifndef COLLIMATORPHYSICS_HH
 #define COLLIMATORPHYSICS_HH
 
-#include <vector>
 #include "Solvers/ParticleMatterInteractionHandler.hh"
+
+#include "AbsBeamline/ElementBase.h"
 #include "Algorithms/Vektor.h"
-#include "AbsBeamline/Component.h"
-#include "AbsBeamline/CCollimator.h"
-#include "AbsBeamline/FlexibleCollimator.h"
-#include "AbsBeamline/Degrader.h"
 #include <gsl/gsl_rng.h>
 
 #include "Utility/IpplTimings.h"
 
-class ElementBase;
+#include <memory>
+#include <utility>
+#include <string>
+#include <vector>
 
 template <class T, unsigned Dim>
 class PartBunchBase;
diff --git a/src/Classic/Structure/LossDataSink.cpp b/src/Classic/Structure/LossDataSink.cpp
index fe465ead4..121b8118b 100644
--- a/src/Classic/Structure/LossDataSink.cpp
+++ b/src/Classic/Structure/LossDataSink.cpp
@@ -1,6 +1,5 @@
 #include "Structure/LossDataSink.h"
 
-#include "Ippl.h"
 #include "Utilities/Options.h"
 #include "AbstractObjects/OpalData.h"
 #include "Utilities/GeneralClassicException.h"
diff --git a/src/Classic/Structure/LossDataSink.h b/src/Classic/Structure/LossDataSink.h
index cb3d14724..771c8c89e 100644
--- a/src/Classic/Structure/LossDataSink.h
+++ b/src/Classic/Structure/LossDataSink.h
@@ -2,11 +2,10 @@
 //  Copyright & License: See Copyright.readme in src directory
 //
 
-#ifndef OPAL_LOSSOUTPUT_H_
-#define OPAL_LOSSOUTPUT_H_
+#ifndef LOSSDATASINK_H_
+#define LOSSDATASINK_H_
 
 //////////////////////////////////////////////////////////////
-#include "Utility/IpplInfo.h"
 #include "Algorithms/Vektor.h"
 #include "AbsBeamline/ElementBase.h"
 #include "AbstractObjects/OpalData.h"
@@ -17,7 +16,6 @@
 #include <functional>
 #include <set>
 
-#include <hdf5.h>
 #include "H5hut.h"
 
 struct SetStatistics {
@@ -199,4 +197,4 @@ std::set<SetStatistics> LossDataSink::computeStatistics(unsigned int numStatisti
 // c-basic-offset: 4
 // indent-tabs-mode: nil
 // require-final-newline: nil
-// End:
+// End:
\ No newline at end of file
diff --git a/src/Classic/Structure/MeshGenerator.h b/src/Classic/Structure/MeshGenerator.h
index 018f7713e..ddd428e90 100644
--- a/src/Classic/Structure/MeshGenerator.h
+++ b/src/Classic/Structure/MeshGenerator.h
@@ -1,4 +1,23 @@
-#include "AbsBeamline/ElementBase.h"
+//
+// Mesh Generator
+//
+// Copyright (c) 2008-2020
+// Paul Scherrer Institut, Villigen PSI, Switzerland
+// All rights reserved.
+//
+// OPAL is licensed under GNU GPL version 3.
+//
+
+#ifndef MESHGENERATOR_H_
+#define MESHGENERATOR_H_
+
+#include "Algorithms/Vektor.h"
+
+#include <string>
+#include <utility>
+#include <vector>
+
+class ElementBase;
 
 class MeshData {
 public:
@@ -41,6 +60,8 @@ private:
     std::vector<MeshData> elements_m;
 };
 
+#endif
+
 // vi: set et ts=4 sw=4 sts=4:
 // Local Variables:
 // mode:c
diff --git a/src/Classic/Structure/PeakFinder.cpp b/src/Classic/Structure/PeakFinder.cpp
index 5c6150269..e06688c5c 100644
--- a/src/Classic/Structure/PeakFinder.cpp
+++ b/src/Classic/Structure/PeakFinder.cpp
@@ -5,7 +5,9 @@
 #include <iterator>
 
 #include "AbstractObjects/OpalData.h"
-#include "Ippl.h"
+
+#include "Message/GlobalComm.h"
+#include "Utility/IpplInfo.h"
 
 PeakFinder::PeakFinder(std::string elem, double min,
                        double max, double binWidth, bool singlemode)
diff --git a/src/Classic/Structure/PeakFinder.h b/src/Classic/Structure/PeakFinder.h
index a6b0777e8..b74916ee9 100644
--- a/src/Classic/Structure/PeakFinder.h
+++ b/src/Classic/Structure/PeakFinder.h
@@ -14,7 +14,6 @@
  * used for the cyclotron probe element.
  */
 
-#include "Utility/IpplInfo.h"
 #include "Algorithms/Vektor.h"
 
 #include <fstream>
diff --git a/src/Classic/TrimCoils/OpalTrimCoil.cpp b/src/Classic/TrimCoils/OpalTrimCoil.cpp
index 992e6638e..270c5f6cf 100644
--- a/src/Classic/TrimCoils/OpalTrimCoil.cpp
+++ b/src/Classic/TrimCoils/OpalTrimCoil.cpp
@@ -31,7 +31,7 @@
 #include "TrimCoils/TrimCoilPhaseFit.h"
 #include "TrimCoils/TrimCoilMirrored.h"
 #include "Utilities/OpalException.h"
-#include "Utility/IpplInfo.h"
+#include "Utility/Inform.h"
 
 extern Inform *gmsg;
 
diff --git a/src/Classic/TrimCoils/OpalTrimCoil.h b/src/Classic/TrimCoils/OpalTrimCoil.h
index 4591db333..67e0a7570 100644
--- a/src/Classic/TrimCoils/OpalTrimCoil.h
+++ b/src/Classic/TrimCoils/OpalTrimCoil.h
@@ -31,6 +31,7 @@
 #include "AbstractObjects/Definition.h"
 
 class Attribute;
+class Inform;
 class TrimCoil;
 
 class OpalTrimCoil: public Definition {
diff --git a/src/Distribution/ClosedOrbitFinder.h b/src/Distribution/ClosedOrbitFinder.h
index aede80ce4..27771a60b 100644
--- a/src/Distribution/ClosedOrbitFinder.h
+++ b/src/Distribution/ClosedOrbitFinder.h
@@ -37,7 +37,6 @@
 #include <utility>
 #include <vector>
 
-#include "Utilities/Options.h"
 #include "Utilities/Options.h"
 #include "Utilities/OpalException.h"
 #include "Physics/Physics.h"
diff --git a/src/Distribution/Distribution.cpp b/src/Distribution/Distribution.cpp
index 4a88b8643..8e6ae954e 100644
--- a/src/Distribution/Distribution.cpp
+++ b/src/Distribution/Distribution.cpp
@@ -27,7 +27,6 @@
 #include "AbstractObjects/OpalData.h"
 #include "Algorithms/PartBins.h"
 #include "Algorithms/PartBunchBase.h"
-#include "Structure/Beam.h"
 #include "Algorithms/PartBinsCyc.h"
 #include "BasicActions/Option.h"
 #include "Distribution/LaserProfile.h"
diff --git a/src/Distribution/SigmaGenerator.h b/src/Distribution/SigmaGenerator.h
index f70f034dc..30b46d2f3 100644
--- a/src/Distribution/SigmaGenerator.h
+++ b/src/Distribution/SigmaGenerator.h
@@ -33,16 +33,19 @@
 #define SIGMAGENERATOR_H
 
 #include <array>
+#include <fstream>
+#include <functional>
 #include <string>
 #include <vector>
 
+#include <boost/numeric/ublas/matrix.hpp>
+
 #include "AbsBeamline/Cyclotron.h"
 #include "FixedAlgebra/FTps.h"
 #include "Physics/Physics.h"
 
 #include "Distribution/RealDiracMatrix.h"
 
-
 class SigmaGenerator
 {
 public:
@@ -54,7 +57,7 @@ public:
     typedef RealDiracMatrix::vector_t vector_t;
     /// Container for storing the properties for each angle
     typedef std::vector<double> container_t;
-    /// Type of the truncated powere series
+    /// Type of the truncated power series
     typedef FTps<double,2*3> Series;
     /// Type of a map
     typedef FVps<double,2*3> Map;
diff --git a/src/Elements/OpalElement.h b/src/Elements/OpalElement.h
index 4c43fae21..c5eb7390b 100644
--- a/src/Elements/OpalElement.h
+++ b/src/Elements/OpalElement.h
@@ -21,6 +21,7 @@
 #include "AbstractObjects/Element.h"
 #include "MemoryManagement/OwnPtr.h"
 #include <map>
+#include <string>
 
 class Statement;
 
diff --git a/src/Main.cpp b/src/Main.cpp
index f834b1483..0e286dcf0 100644
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -17,9 +17,6 @@
 
 #include "opal.h"
 
-Ippl *ippl;
-Inform *gmsg;
-
 #include "H5hut.h"
 
 #include "AbstractObjects/OpalData.h"
@@ -33,52 +30,37 @@ Inform *gmsg;
 
 #include "BasicActions/Option.h"
 #include "Utilities/Options.h"
-#include "Utilities/Options.h"
 #include "Utilities/OpalException.h"
 #include "Utilities/EarlyLeaveException.h"
 #include "Utilities/Util.h"
 
+#include "Util/SDDSParser/SDDSParserException.h"
+
 #include "OPALconfig.h"
 
 #ifdef ENABLE_AMR
 #include <AMReX_ParallelDescriptor.H>
 #endif
-/*
-  Includes related to the optimizer
-*/
-#include "boost/smart_ptr.hpp"
-
-#include "Pilot/Pilot.h"
-#include "Util/CmdArguments.h"
-#include "Util/OptPilotException.h"
-
-#include "Optimizer/EA/FixedPisaNsga2.h"
-#include "Optimizer/EA/BlendCrossover.h"
-#include "Optimizer/EA/IndependentBitMutation.h"
-
-#include "Optimize/OpalSimulation.h"
-
-#include "Comm/CommSplitter.h"
-#include "Comm/Topology/NoCommTopology.h"
-#include "Comm/Splitter/ManyMasterSplit.h"
-#include "Comm/MasterGraph/SocialNetworkGraph.h"
-
-#include "Expression/Parser/function.hpp"
-#include "Expression/FromFile.h"
-#include "Expression/SumErrSq.h"
-#include "Expression/SDDSVariable.h"
-#include "Expression/RadialPeak.h"
-#include "Expression/SumErrSqRadialPeak.h"
-#include "Expression/ProbeVariable.h"
+
+// IPPL
+#include "Message/Communicate.h"
+#include "Utility/Inform.h"
+#include "Utility/IpplException.h"
+#include "Utility/IpplInfo.h"
+#include "Utility/IpplTimings.h"
 
 #include <gsl/gsl_errno.h>
 
 #include <boost/filesystem.hpp>
-#include <boost/algorithm/string/predicate.hpp>
+#include <boost/system/error_code.hpp>
 
 #include <cstring>
+#include <iomanip>
+#include <iostream>
 #include <set>
-#include <algorithm>
+
+Ippl *ippl;
+Inform *gmsg;
 
 namespace {
     void errorHandlerGSL(const char *reason,
diff --git a/src/OpalParser/IfStatement.cpp b/src/OpalParser/IfStatement.cpp
index f0483dbf1..aec7f27a9 100644
--- a/src/OpalParser/IfStatement.cpp
+++ b/src/OpalParser/IfStatement.cpp
@@ -26,6 +26,7 @@
 #include "Parser/TokenStream.h"
 #include "Utilities/ParseError.h"
 
+#include "Utility/IpplInfo.h"
 
 // class IfStatement
 //   Statement of the form "IF ( <condition> ) <statement>".
diff --git a/src/OpalParser/OpalParser.cpp b/src/OpalParser/OpalParser.cpp
index 8cd8ecbc0..839af98d1 100644
--- a/src/OpalParser/OpalParser.cpp
+++ b/src/OpalParser/OpalParser.cpp
@@ -41,7 +41,9 @@
 #include <new>
 #include <boost/algorithm/string.hpp>
 
-#include <Ippl.h>
+#include "Message/GlobalComm.h"
+#include "Utility/Inform.h"
+#include "Utility/IpplInfo.h"
 
 using namespace Expressions;
 
diff --git a/src/OpalParser/WhileStatement.cpp b/src/OpalParser/WhileStatement.cpp
index cd453c945..7f16066f6 100644
--- a/src/OpalParser/WhileStatement.cpp
+++ b/src/OpalParser/WhileStatement.cpp
@@ -17,6 +17,7 @@
 // ------------------------------------------------------------------------
 
 #include "OpalParser/WhileStatement.h"
+
 #include "AbstractObjects/OpalData.h"
 #include "AbstractObjects/Attribute.h"
 #include "Attributes/Attributes.h"
@@ -26,6 +27,8 @@
 #include "Parser/TokenStream.h"
 #include "Utilities/ParseError.h"
 
+#include "Utility/IpplInfo.h"
+
 // class WhileStatement
 //   Statement of the form "WHILE ( <condition> ) <statement>".
 // ------------------------------------------------------------------------
diff --git a/src/Sample/Sampler.cpp b/src/Sample/Sampler.cpp
index 1facdcfe9..ebfd81850 100644
--- a/src/Sample/Sampler.cpp
+++ b/src/Sample/Sampler.cpp
@@ -32,6 +32,7 @@
 #include "Util/MPIHelper.h"
 
 #include <boost/property_tree/json_parser.hpp>
+#include <boost/property_tree/ptree.hpp>
 
 #include <boost/filesystem.hpp>
 
diff --git a/src/Sample/Sampler.h b/src/Sample/Sampler.h
index a8db3f192..2f77350f9 100644
--- a/src/Sample/Sampler.h
+++ b/src/Sample/Sampler.h
@@ -29,6 +29,8 @@
 #include <sstream>
 #include <vector>
 #include <map>
+#include <memory>
+#include <queue>
 #include <utility>
 #include <fstream>
 #include <list>
@@ -44,9 +46,6 @@
 #include "Sample/SamplingMethod.h"
 
 #include <boost/smart_ptr.hpp>
-#include <boost/chrono.hpp>
-#include <boost/property_tree/ptree.hpp>
-
 
 class Sampler : public Optimizer {
 
diff --git a/src/Solvers/BoxCornerDomain.h b/src/Solvers/BoxCornerDomain.h
index 2a6d8f594..02bbc1a9b 100644
--- a/src/Solvers/BoxCornerDomain.h
+++ b/src/Solvers/BoxCornerDomain.h
@@ -28,9 +28,9 @@
 
 #include <map>
 #include <string>
-#include <cmath>
-#include "Solvers/RegularDomain.h"
+#include <utility>
 
+#include "Solvers/RegularDomain.h"
 
 /*
 
@@ -164,4 +164,4 @@ private:
 // c-basic-offset: 4
 // indent-tabs-mode: nil
 // require-final-newline: nil
-// End:
+// End:
\ No newline at end of file
diff --git a/src/Solvers/FFTBoxPoissonSolver.h b/src/Solvers/FFTBoxPoissonSolver.h
index 66dbb9f54..61876efb6 100644
--- a/src/Solvers/FFTBoxPoissonSolver.h
+++ b/src/Solvers/FFTBoxPoissonSolver.h
@@ -23,11 +23,16 @@
 
 //////////////////////////////////////////////////////////////
 #include "PoissonSolver.h"
+
+#include "FFT/FFT.h"
+
 class PartBunch;
 //////////////////////////////////////////////////////////////
 
 class FFTBoxPoissonSolver : public PoissonSolver {
 public:
+    typedef FFT<SineTransform, 3, double>            SINE_t;
+
     // constructor and destructor
     FFTBoxPoissonSolver(PartBunch &bunch, std::string greensFuntion);
 
diff --git a/src/Solvers/FFTPoissonSolver.h b/src/Solvers/FFTPoissonSolver.h
index 2ead1b25d..8fb703bbc 100644
--- a/src/Solvers/FFTPoissonSolver.h
+++ b/src/Solvers/FFTPoissonSolver.h
@@ -32,12 +32,16 @@
 //////////////////////////////////////////////////////////////
 #include "PoissonSolver.h"
 
+#include "FFT/FFT.h"
+
 class PartBunch;
 
 //////////////////////////////////////////////////////////////
 
 class FFTPoissonSolver : public PoissonSolver {
 public:
+    typedef FFT<RCTransform, 3, double>              FFT_t;
+
     // constructor and destructor
     FFTPoissonSolver(PartBunch &bunch, std::string greensFuntion);
 
diff --git a/src/Solvers/IrregularDomain.h b/src/Solvers/IrregularDomain.h
index fc991c4d6..03dba2429 100644
--- a/src/Solvers/IrregularDomain.h
+++ b/src/Solvers/IrregularDomain.h
@@ -26,9 +26,10 @@
 #ifndef IRREGULAR_DOMAIN_H
 #define IRREGULAR_DOMAIN_H
 
-#include <vector>
+#include <map>
 #include <string>
-#include "Algorithms/PBunchDefs.h"
+#include "Algorithms/Vektor.h"
+#include "Algorithms/Quaternion.h"
 
 /// enumeration corresponding to different interpolation methods at the boundary
 enum {
diff --git a/src/Solvers/P3MPoissonSolver.h b/src/Solvers/P3MPoissonSolver.h
index 20ea43d16..12c4336dd 100644
--- a/src/Solvers/P3MPoissonSolver.h
+++ b/src/Solvers/P3MPoissonSolver.h
@@ -33,7 +33,10 @@ const unsigned Dim = 3;
 #include <memory>
 //////////////////////////////////////////////////////////////
 #include "PoissonSolver.h"
-#include "Algorithms/PartBunchBase.h"
+
+#include "FFT/FFT.h"
+
+//#include "Algorithms/PartBunchBase.h"
 
 template <class T, unsigned Dim>
 class PartBunchBase;
@@ -42,6 +45,9 @@ class PartBunchBase;
 
 class P3MPoissonSolver : public PoissonSolver {
 public:
+
+    typedef FFT<CCTransform, 3, double>              FFTC_t;
+
     // constructor and destructor
     P3MPoissonSolver(Mesh_t *mesh, FieldLayout_t *fl, double interaction_radius, double alpha, double eps);
 
diff --git a/src/Solvers/PoissonSolver.h b/src/Solvers/PoissonSolver.h
index 84aa754ce..a82fadf4a 100644
--- a/src/Solvers/PoissonSolver.h
+++ b/src/Solvers/PoissonSolver.h
@@ -4,6 +4,8 @@
 //////////////////////////////////////////////////////////////
 #include "Algorithms/PBunchDefs.h"
 
+#include "Field/Field.h"
+
 #ifdef ENABLE_AMR
     #include "Utilities/OpalException.h"
 #endif
@@ -12,6 +14,11 @@ template <class T, unsigned Dim>
 class PartBunchBase;
 
 class PoissonSolver {
+
+protected:
+    typedef Field<int, 3, Mesh_t, Center_t>                  IField_t;
+    typedef Field<std::complex<double>, 3, Mesh_t, Center_t> CxField_t;
+
 public:
 
     // given a charge-density field rho and a set of mesh spacings hr,
diff --git a/src/Structure/Beam.h b/src/Structure/Beam.h
index 0bb1657a0..5f221a50c 100644
--- a/src/Structure/Beam.h
+++ b/src/Structure/Beam.h
@@ -22,6 +22,7 @@
 #include "Algorithms/PartData.h"
 
 #include <ostream>
+#include <string>
 
 class Inform;
 
diff --git a/src/Structure/DataSink.cpp b/src/Structure/DataSink.cpp
index 017025569..a23503889 100644
--- a/src/Structure/DataSink.cpp
+++ b/src/Structure/DataSink.cpp
@@ -28,6 +28,8 @@
 
 #include "Structure/DataSink.h"
 
+#include "Utility/FieldDebugFunctions.h"
+
 #include "OPALconfig.h"
 #include "AbstractObjects/OpalData.h"
 #include "Utilities/Options.h"
@@ -39,6 +41,8 @@
 
 #ifdef __linux__
     #include "MemoryProfiler.h"
+#else
+    #include "MemoryWriter.h"
 #endif
 
 
@@ -49,17 +53,11 @@
 
 
 #include "LBalWriter.h"
-#include "MemoryWriter.h"
 
 #ifdef ENABLE_AMR
     #include "GridLBalWriter.h"
 #endif
 
-
-#include <boost/filesystem.hpp>
-#include <boost/regex.hpp>
-
-#include <queue>
 #include <sstream>
 
 DataSink::DataSink()
@@ -176,8 +174,6 @@ void DataSink::writeImpactStatistics(const PartBunchBase<double, 3> *beam, long
 
         std::unique_ptr<Inform> ofp(new Inform(NULL, ffn.c_str(), Inform::APPEND, 0));
         Inform &fid = *ofp;
-        setInform(fid);
-
         fid.precision(6);
         fid << std::setiosflags(std::ios::scientific);
         double t = beam->getT() * 1.0e9;
diff --git a/src/Structure/DataSink.h b/src/Structure/DataSink.h
index f33e6ca39..7e3abf0da 100644
--- a/src/Structure/DataSink.h
+++ b/src/Structure/DataSink.h
@@ -28,26 +28,33 @@
 #ifndef _OPAL_DATA_SINK_H
 #define _OPAL_DATA_SINK_H
 
-#include "Algorithms/PBunchDefs.h"
+#include "Algorithms/Vektor.h"
 
+#include "SDDSWriter.h"
 #include "StatWriter.h"
 #include "H5Writer.h"
 #include "MultiBunchDump.h"
 
+#include <iomanip>
+#include <memory>
+#include <string>
+#include <vector>
+
 template <class T, unsigned Dim>
 class PartBunchBase;
 class BoundaryGeometry;
 class H5PartWrapper;
+class MultiBunchHandler;
 
 class DataSink {
-public:
+private:
     typedef StatWriter::losses_t            losses_t;
     typedef std::unique_ptr<StatWriter>     statWriter_t;
     typedef std::unique_ptr<SDDSWriter>     sddsWriter_t;
     typedef std::unique_ptr<H5Writer>       h5Writer_t;
     typedef std::unique_ptr<MultiBunchDump> mbWriter_t;
     
-    
+public:
     /** \brief Default constructor.
      *
      * The default constructor is called at the start of a new calculation (as
diff --git a/src/Structure/H5PartWrapper.h b/src/Structure/H5PartWrapper.h
index 9daceaf80..e21368c8c 100644
--- a/src/Structure/H5PartWrapper.h
+++ b/src/Structure/H5PartWrapper.h
@@ -6,15 +6,19 @@
 //
 
 /*!
-  H5PartWrapper: a class that manages a calls to H5Part
+  H5PartWrapper: a class that manages calls to H5Part
 */
 
-#include "Algorithms/PBunchDefs.h"
-#include "Algorithms/PartBunchBase.h"
-#include "Utilities/OpalException.h"
+template <class T, unsigned Dim>
+class PartBunchBase;
+
+#include "Utility/IpplInfo.h"
 
 #include "H5hut.h"
 
+#include <map>
+#include <string>
+
 #define REPORTONERROR(rc) H5PartWrapper::reportOnError(rc, __FILE__, __LINE__)
 #define READFILEATTRIB(type, file, name, value) REPORTONERROR(H5ReadFileAttrib##type(file, name, value));
 #define WRITESTRINGFILEATTRIB(file, name, value) REPORTONERROR(H5WriteFileAttribString(file, name, value));
diff --git a/src/Structure/H5PartWrapperForPC.cpp b/src/Structure/H5PartWrapperForPC.cpp
index 09fc25938..58c5454c2 100644
--- a/src/Structure/H5PartWrapperForPC.cpp
+++ b/src/Structure/H5PartWrapperForPC.cpp
@@ -11,8 +11,6 @@
 #include "Utilities/Util.h"
 #include "Physics/Physics.h"
 
-#include <boost/filesystem.hpp>
-
 #include <sstream>
 #include <set>
 
diff --git a/src/Structure/H5PartWrapperForPC.h b/src/Structure/H5PartWrapperForPC.h
index 0b40133dd..9abe5eaff 100644
--- a/src/Structure/H5PartWrapperForPC.h
+++ b/src/Structure/H5PartWrapperForPC.h
@@ -7,8 +7,7 @@
 
 #include "Structure/H5PartWrapper.h"
 
-#include "Algorithms/PBunchDefs.h"
-#include "Utilities/OpalException.h"
+#include "Algorithms/Vektor.h"
 
 #include "H5hut.h"
 
diff --git a/src/Structure/H5PartWrapperForPT.cpp b/src/Structure/H5PartWrapperForPT.cpp
index 8fe3529b4..9f7e02e33 100644
--- a/src/Structure/H5PartWrapperForPT.cpp
+++ b/src/Structure/H5PartWrapperForPT.cpp
@@ -6,12 +6,13 @@
 
 #include "OPALconfig.h"
 #include "AbstractObjects/OpalData.h"
+#include "Algorithms/PartBunchBase.h"
+#include "Algorithms/Vektor.h"
 #include "Utilities/Options.h"
 #include "Utilities/Util.h"
 #include "Physics/Physics.h"
 
 #include "h5core/h5_types.h"
-#include <boost/filesystem.hpp>
 
 #include <sstream>
 #include <set>
diff --git a/src/Structure/H5PartWrapperForPT.h b/src/Structure/H5PartWrapperForPT.h
index 7d7e0924b..800228960 100644
--- a/src/Structure/H5PartWrapperForPT.h
+++ b/src/Structure/H5PartWrapperForPT.h
@@ -11,9 +11,6 @@
 
 #include "Structure/H5PartWrapper.h"
 
-#include "Algorithms/PBunchDefs.h"
-#include "Utilities/OpalException.h"
-
 #include "H5hut.h"
 
 class H5PartWrapperForPT: public H5PartWrapper {
diff --git a/src/Structure/IpplInfoWrapper.h b/src/Structure/IpplInfoWrapper.h
index 31a3195aa..cd4fa1478 100644
--- a/src/Structure/IpplInfoWrapper.h
+++ b/src/Structure/IpplInfoWrapper.h
@@ -9,7 +9,7 @@
   Class documentation
 */
 
-#include "Ippl.h"
+#include "Utility/IpplInfo.h"
 
 class IpplInfoWrapper {
 public:
diff --git a/src/Structure/SDDSWriter.h b/src/Structure/SDDSWriter.h
index 757dad16f..39e1d1a4f 100644
--- a/src/Structure/SDDSWriter.h
+++ b/src/Structure/SDDSWriter.h
@@ -31,7 +31,6 @@
 #include <sstream>
 
 #include <boost/filesystem.hpp>
-#include <boost/variant.hpp>
 
 #include "Structure/SDDSColumn.h"
 #include "Structure/SDDSColumnSet.h"
diff --git a/src/Track/TrackEnd.h b/src/Track/TrackEnd.h
index dfe5debb7..48496a9eb 100644
--- a/src/Track/TrackEnd.h
+++ b/src/Track/TrackEnd.h
@@ -21,7 +21,6 @@
 #include "AbstractObjects/Action.h"
 
 class Sequence;
-class TrackParser;
 
 
 // Class TrackEnd
diff --git a/src/opal.cpp b/src/opal.cpp
index 09961c5b0..bb8625b6c 100644
--- a/src/opal.cpp
+++ b/src/opal.cpp
@@ -3,7 +3,6 @@
 extern Ippl *ippl;
 extern Inform *gmsg;
 
-
 #include "AbstractObjects/OpalData.h"
 #include "OpalConfigure/Configure.h"
 #include "OpalParser/OpalParser.h"
@@ -19,6 +18,12 @@ extern Inform *gmsg;
     #include <AMReX.H>
 #endif
 
+#include "Message/Communicate.h"
+
+#include <fstream>
+#include <iostream>
+#include <limits>
+#include <string>
 
 int run_opal(char */*args*/[], std::string inputfile, int restartStep,
              int infoLevel, int warnLevel, MPI_Comm comm)
diff --git a/src/opal.h b/src/opal.h
index a53b5d872..15e46cc57 100644
--- a/src/opal.h
+++ b/src/opal.h
@@ -1,8 +1,7 @@
 #ifndef __OPAL_H__
 #define __OPAL_H__
 
-#include "Ippl.h"
-
+#include "Utility/IpplInfo.h"
 
 int run_opal(char *arg[],
              std::string inputfile,
diff --git a/tests/ippl_src/Index/Index.cpp b/tests/ippl_src/Index/Index.cpp
index 6f66973b9..ed58fded3 100644
--- a/tests/ippl_src/Index/Index.cpp
+++ b/tests/ippl_src/Index/Index.cpp
@@ -2,6 +2,7 @@
 
 #include "opal_test_utilities/SilenceTest.h"
 
+#include "Field/Field.h"
 #include "Index/SOffset.h"
 
 #include <iostream>
diff --git a/tests/ippl_src/Meshes/Average.cpp b/tests/ippl_src/Meshes/Average.cpp
index 362f6384f..dbecef987 100644
--- a/tests/ippl_src/Meshes/Average.cpp
+++ b/tests/ippl_src/Meshes/Average.cpp
@@ -4,6 +4,7 @@
 
 #include "gtest/gtest.h"
 
+#include "Field/Field.h"
 #include "Meshes/UniformCartesian.h"
 
 // set dimensionality and problem size
diff --git a/tests/ippl_src/Meshes/CartesianCentering.cpp b/tests/ippl_src/Meshes/CartesianCentering.cpp
index 6fe18d7e4..beb12ee8a 100644
--- a/tests/ippl_src/Meshes/CartesianCentering.cpp
+++ b/tests/ippl_src/Meshes/CartesianCentering.cpp
@@ -14,10 +14,10 @@
 namespace {
     void hardCodedOutput(std::string filename); // Prototype of function defined below.
     bool thediff(std::string filename1, std::string filename2);
-
-    CenteringEnum zz[2] = {CELL, VERTEX};
 }
 
+CenteringEnum zz[2] = {CELL, VERTEX};
+
 // template definitions
 CenteringEnum CCCEnums<2U,1U,0U>::allCell[2U*1U];
 CenteringEnum CCCEnums<3U,1U,1U>::allFace[3U*1U];
diff --git a/tests/ippl_src/Particle/EdgeCentering.cpp b/tests/ippl_src/Particle/EdgeCentering.cpp
index 12fc7770b..dec833896 100644
--- a/tests/ippl_src/Particle/EdgeCentering.cpp
+++ b/tests/ippl_src/Particle/EdgeCentering.cpp
@@ -2,7 +2,7 @@
 // #include "Algorithms/PBunchDefs.h"
 // #include "Algorithms/PartBunch.h"
 // #include "Algorithms/PartData.h"
-#include "Particle/IntCIC.h"
+//#include "Particle/IntCIC.h"
 #include "Particle/ParticleSpatialLayout.h"
 #include "Particle/ParticleAttrib.h"
 #include "Meshes/UniformCartesian.h"
@@ -16,13 +16,10 @@
 #define GUARDCELLSIZE 1
 #define DIM 3
 
-typedef IntCIC                                                IntrplCIC_t;
-
 typedef Vektor<double, DIM>                                   Vector_t;
 typedef ParticleSpatialLayout<double, DIM>::ParticlePos_t     Ppos_t;
 typedef ParticleSpatialLayout<double, DIM>::ParticleIndex_t   PID_t;
 typedef ParticleAttrib<double>                                Pscalar_t;
-typedef InterpolatorTraits<double, DIM, IntrplCIC_t>::Cache_t Pcache_t;
 
 typedef UniformCartesian<DIM>                                 Mesh_t;
 typedef ParticleSpatialLayout< double, DIM, Mesh_t>           PLayout_t;
-- 
GitLab