diff --git a/src/adjmat/ActionWithInputMatrix.cpp b/src/adjmat/ActionWithInputMatrix.cpp
index 5aed42c85b983999d871534415435222446fddba..8a91e23614aeed887354ad1a30af50e2bd68544a 100644
--- a/src/adjmat/ActionWithInputMatrix.cpp
+++ b/src/adjmat/ActionWithInputMatrix.cpp
@@ -80,7 +80,7 @@ double ActionWithInputMatrix::retrieveConnectionValue( const unsigned& i, const
   if( !mymatrix->matrixElementIsActive( i, j ) ) return 0;
   unsigned myelem = mymatrix->getStoreIndexFromMatrixIndices( i, j );
 
-  unsigned vi; double df;
+  // unsigned vi; double df;
   mymatrix->retrieveValueWithIndex( myelem, false, vals );
   return vals[0]*vals[1];       // (mymatrix->function)->transformStoredValues( vals, vi, df );
 }
diff --git a/src/adjmat/AdjacencyMatrixVessel.cpp b/src/adjmat/AdjacencyMatrixVessel.cpp
index 65dfeb0adba27afacbce2179c34cc7ce1c896290..72e155463bfd042b4edcff4c04b7bff741918983 100644
--- a/src/adjmat/AdjacencyMatrixVessel.cpp
+++ b/src/adjmat/AdjacencyMatrixVessel.cpp
@@ -85,7 +85,6 @@ void AdjacencyMatrixVessel::getMatrixIndices( const unsigned& code, unsigned& i,
 }
 
 void AdjacencyMatrixVessel::retrieveMatrix( DynamicList<unsigned>& myactive_elements, Matrix<double>& mymatrix ) {
-  unsigned vin; double df;
   myactive_elements.deactivateAll(); std::vector<double> vals( getNumberOfComponents() );
   for(unsigned i=0; i<getNumberOfStoredValues(); ++i) {
     retrieveSequentialValue( i, false, vals );
diff --git a/src/analysis/PCA.cpp b/src/analysis/PCA.cpp
index d6350def936323a46c4dea5852a385256fc60e40..0e9cbeadc5326d63ece7c777f4ba3b41d3c232ab 100644
--- a/src/analysis/PCA.cpp
+++ b/src/analysis/PCA.cpp
@@ -164,7 +164,7 @@ void PCA::performAnalysis() {
   // Calculate the average displacement from the first frame
   double norm=getWeight(0);
   for(unsigned i=1; i<getNumberOfDataPoints(); ++i) {
-    double d = data[0]->calc( data[i]->getReferencePositions(), getPbc(), getArguments(), data[i]->getReferenceArguments(), mypack, true );
+    data[0]->calc( data[i]->getReferencePositions(), getPbc(), getArguments(), data[i]->getReferenceArguments(), mypack, true );
     // Accumulate average displacement of arguments (Here PBC could do fucked up things - really needs Berry Phase ) GAT
     for(unsigned j=0; j<getNumberOfArguments(); ++j) sarg[j] += 0.5*getWeight(i)*mypack.getArgumentDerivative(j);
     // Accumulate average displacement of position
@@ -183,7 +183,7 @@ void PCA::performAnalysis() {
   Matrix<double> covar( getNumberOfArguments()+3*getNumberOfAtoms(), getNumberOfArguments()+3*getNumberOfAtoms() ); covar=0;
   for(unsigned i=0; i<getNumberOfDataPoints(); ++i) {
     // double d = data[i]->calc( spos, getPbc(), getArguments(), sarg, mypack, true );
-    double d = data[0]->calc( data[i]->getReferencePositions(), getPbc(), getArguments(), data[i]->getReferenceArguments(), mypack, true );
+    data[0]->calc( data[i]->getReferencePositions(), getPbc(), getArguments(), data[i]->getReferenceArguments(), mypack, true );
     for(unsigned jarg=0; jarg<getNumberOfArguments(); ++jarg) {
       // Need sorting for PBC with GAT
       double jarg_d = 0.5*mypack.getArgumentDerivative(jarg) + data[0]->getReferenceArguments()[jarg] - sarg[jarg];
diff --git a/src/bias/LWalls.cpp b/src/bias/LWalls.cpp
index d42c9ee2079d14395e99b727afadc68137084478..2fc3b66c6e0de1882ca8f193045d397af163c06a 100644
--- a/src/bias/LWalls.cpp
+++ b/src/bias/LWalls.cpp
@@ -129,14 +129,14 @@ void LWalls::calculate() {
   double ene = 0.0;
   double totf2 = 0.0;
   for(unsigned i=0; i<getNumberOfArguments(); ++i) {
+    double f = 0.0;
     const double cv=difference(i,at[i],getArgument(i));
-    const double k=kappa[i];
-    const double exponent=exp[i];
-    const double epsilon=eps[i];
     const double off=offset[i];
+    const double epsilon=eps[i];
     const double lscale = (cv-off)/epsilon;
-    double f = 0.0;
     if( lscale < 0.) {
+      const double k=kappa[i];
+      const double exponent=exp[i];
       double power = pow( lscale, exponent );
       f = -( k / epsilon ) * exponent * power / lscale;
       ene += k * power;
diff --git a/src/bias/MaxEnt.cpp b/src/bias/MaxEnt.cpp
index 16de8749c964a65aca0d53f144eee3e6330385ab..35f5d05397bf5ef0fc4fb8fabaecd203cf36f9fa 100644
--- a/src/bias/MaxEnt.cpp
+++ b/src/bias/MaxEnt.cpp
@@ -341,9 +341,6 @@ MaxEnt::MaxEnt(const ActionOptions&ao):
 ////MEMBER FUNCTIONS
 void MaxEnt::ReadLagrangians(IFile &ifile)
 {
-  unsigned ncv=getNumberOfArguments();
-  double deltat=getTimeStep();
-  double last_checkpoint=getTime();
   double dummy;
   while(ifile.scanField("time",dummy)) {
     for(unsigned j=0; j<getNumberOfArguments(); ++j) {
@@ -430,20 +427,17 @@ void MaxEnt::update_lambda() {
 
   double totalWork_=0.0;
   const double time=getTime();
-  const double deltat=getTimeStep();
   const double step=getStep();
   double KbT=simtemp;
   double learning_rate;
-  double cv;
   if(reweight)
     BetaReweightBias=plumed.getBias()/KbT;
   else
     BetaReweightBias=0.0;
 
   for(unsigned i=0; i<getNumberOfArguments(); ++i) {
-    double sigma2=pow(sigma,2.0);
     const double k=kappa[i];
-    cv=(getArgument(i)+compute_error(error_type,lambda[i])-at[i]);
+    double cv=(getArgument(i)+compute_error(error_type,lambda[i])-at[i]);
     if(reweight)
       learning_rate=1.0*k/(1+step/tau[i]);
     else
diff --git a/src/bias/MetaD.cpp b/src/bias/MetaD.cpp
index ecfb24b599832f626890a2a838fece9c7ec84256..588618b4cb9dc5f512b35b788e19ba4d1b4809fd 100644
--- a/src/bias/MetaD.cpp
+++ b/src/bias/MetaD.cpp
@@ -1892,7 +1892,7 @@ double MetaD::getTransitionBarrierBias() {
     // starting well. With this choice the searches will terminate in one step until
     // transitionwell_[1] is sampled.
   } else {
-    double least_transition_bias, curr_transition_bias;
+    double least_transition_bias;
     vector<double> sink = transitionwells_[0];
     vector<double> source = transitionwells_[1];
     least_transition_bias = BiasGrid_->findMaximalPathMinimum(source, sink);
@@ -1901,7 +1901,7 @@ double MetaD::getTransitionBarrierBias() {
         break;
       }
       source = transitionwells_[i];
-      curr_transition_bias = BiasGrid_->findMaximalPathMinimum(source, sink);
+      double curr_transition_bias = BiasGrid_->findMaximalPathMinimum(source, sink);
       least_transition_bias = fmin(curr_transition_bias, least_transition_bias);
     }
     return least_transition_bias;
diff --git a/src/bias/UWalls.cpp b/src/bias/UWalls.cpp
index 11023898b190af00c0e0077e8dd0e2c397e032c3..b33543ff81a08853206a7f2ec45cd20e9fbbe566 100644
--- a/src/bias/UWalls.cpp
+++ b/src/bias/UWalls.cpp
@@ -128,14 +128,14 @@ void UWalls::calculate() {
   double ene=0.0;
   double totf2=0.0;
   for(unsigned i=0; i<getNumberOfArguments(); ++i) {
+    double f = 0.0;
     const double cv=difference(i,at[i],getArgument(i));
-    const double k=kappa[i];
-    const double exponent=exp[i];
-    const double epsilon=eps[i];
     const double off=offset[i];
+    const double epsilon=eps[i];
     const double uscale = (cv+off)/epsilon;
-    double f = 0.0;
     if( uscale > 0.) {
+      const double k=kappa[i];
+      const double exponent=exp[i];
       double power = pow( uscale, exponent );
       f = -( k / epsilon ) * exponent * power / uscale;
       ene += k * power;
diff --git a/src/crystallization/CubicHarmonicBase.cpp b/src/crystallization/CubicHarmonicBase.cpp
index 272533da908b0cee91c098a87a8589037b93c093..488d6c62bb9e7da008862d26acc818f5f9639522 100644
--- a/src/crystallization/CubicHarmonicBase.cpp
+++ b/src/crystallization/CubicHarmonicBase.cpp
@@ -100,10 +100,10 @@ double CubicHarmonicBase::compute( const unsigned& tindex, multicolvar::AtomValu
   // Calculate the coordination number
   Vector myder, rotateder, fder; unsigned nat=myatoms.getNumberOfAtoms();
 
-  double d2;
   for(unsigned i=1; i<nat; ++i) {
     Vector& distance=myatoms.getPosition(i);
 
+    double d2;
     if ( (d2=distance[0]*distance[0])<rcut2 &&
          (d2+=distance[1]*distance[1])<rcut2 &&
          (d2+=distance[2]*distance[2])<rcut2 &&
diff --git a/src/crystallization/OrientationSphere.cpp b/src/crystallization/OrientationSphere.cpp
index 5fe28bdf56c814f83ceaff555e4b3e9315664c51..8edbf423fc4204333b6012827951b3add8da86f8 100644
--- a/src/crystallization/OrientationSphere.cpp
+++ b/src/crystallization/OrientationSphere.cpp
@@ -69,7 +69,7 @@ OrientationSphere::OrientationSphere(const ActionOptions&ao):
 }
 
 double OrientationSphere::compute( const unsigned& tindex, multicolvar::AtomValuePack& myatoms ) const {
-  double d2, sw, value=0, denom=0, dfunc; Vector ddistance;
+  double sw, value=0, denom=0, dfunc; Vector ddistance;
   unsigned ncomponents=getBaseMultiColvar(0)->getNumberOfQuantities();
   std::vector<double> catom_orient( ncomponents ), this_orient( ncomponents );
   std::vector<double> this_der( ncomponents ), catom_der( ncomponents );
@@ -79,6 +79,7 @@ double OrientationSphere::compute( const unsigned& tindex, multicolvar::AtomValu
 
   for(unsigned i=1; i<myatoms.getNumberOfAtoms(); ++i) {
     Vector& distance=myatoms.getPosition(i);
+    double d2;
     if ( (d2=distance[0]*distance[0])<rcut2 &&
          (d2+=distance[1]*distance[1])<rcut2 &&
          (d2+=distance[2]*distance[2])<rcut2 &&
diff --git a/src/crystallization/Steinhardt.cpp b/src/crystallization/Steinhardt.cpp
index 261c07996bc1c9a8b3f202d3d47082fa0128c567..9c094c20d179d835336bc3621fc31b498315bccc 100644
--- a/src/crystallization/Steinhardt.cpp
+++ b/src/crystallization/Steinhardt.cpp
@@ -76,9 +76,10 @@ void Steinhardt::calculateVector( multicolvar::AtomValuePack& myatoms ) const {
   std::complex<double> ii( 0.0, 1.0 ), dp_x, dp_y, dp_z;
 
   unsigned ncomp=2*tmom+1;
-  double sw, poly_ass, d2, dlen; std::complex<double> powered;
+  double sw, poly_ass, dlen; std::complex<double> powered;
   for(unsigned i=1; i<myatoms.getNumberOfAtoms(); ++i) {
     Vector& distance=myatoms.getPosition(i);  // getSeparation( myatoms.getPosition(0), myatoms.getPosition(i) );
+    double d2;
     if ( (d2=distance[0]*distance[0])<rcut2 &&
          (d2+=distance[1]*distance[1])<rcut2 &&
          (d2+=distance[2]*distance[2])<rcut2 &&
diff --git a/src/gridtools/GridToXYZ.cpp b/src/gridtools/GridToXYZ.cpp
index 69e2e6d0462eead32d60075ea1604251617fe62d..fe784c2a4fc6080d305b5dae64b088189abedbad 100644
--- a/src/gridtools/GridToXYZ.cpp
+++ b/src/gridtools/GridToXYZ.cpp
@@ -92,7 +92,7 @@ GridToXYZ::GridToXYZ(const ActionOptions&ao):
 }
 
 void GridToXYZ::printGrid( OFile& ofile ) const {
-  std::vector<double> point( 3 ); double val;
+  std::vector<double> point( 3 );
   ofile.printf("%u\n",ingrid->getNumberOfPoints());
   ofile.printf("Grid converted to xyz file \n");
   for(unsigned i=0; i<ingrid->getNumberOfPoints(); ++i) {
diff --git a/src/gridtools/GridVessel.cpp b/src/gridtools/GridVessel.cpp
index 196991e6e7c7c312cdc017d2e33f9701415a052f..7ca346450b32fefcbeafb1431fc1aa934b73e8ae 100644
--- a/src/gridtools/GridVessel.cpp
+++ b/src/gridtools/GridVessel.cpp
@@ -120,7 +120,7 @@ void GridVessel::setupFibonacciGrid( const unsigned& np ) {
 
   std::vector<double> icoord( dimension ), jcoord( dimension );
   // Find minimum distance between each pair of points
-  std::vector<unsigned> tindices( dimension ); std::vector<double> mindists( npoints );
+  std::vector<double> mindists( npoints );
   for(unsigned i=0; i<npoints; ++i) {
     getFibonacciCoordinates( i, icoord ); mindists[i] = 0;
     for(unsigned j=0; j<npoints; ++j) {
diff --git a/src/isdb/EMMI.cpp b/src/isdb/EMMI.cpp
index 5c49e5e9a7925eae5fa3c8fa7f792e7aba88b91c..8281b56f8a2928aa9a7652b395775ee0554ceb65 100644
--- a/src/isdb/EMMI.cpp
+++ b/src/isdb/EMMI.cpp
@@ -416,15 +416,16 @@ void EMMI::check_GMM_d(VectorGeneric<6> &cov, double w)
 // read GMM data file in PLUMED format:
 void EMMI::get_GMM_d(string GMM_file)
 {
-  int idcomp, beta;
-  double w, m0, m1, m2;
   VectorGeneric<6> cov;
 
 // open file
   IFile *ifile = new IFile();
   if(ifile->FileExist(GMM_file)) {
     ifile->open(GMM_file);
+    int idcomp;
     while(ifile->scanField("Id",idcomp)) {
+      int beta;
+      double w, m0, m1, m2;
       ifile->scanField("Weight",w);
       ifile->scanField("Mean_0",m0);
       ifile->scanField("Mean_1",m1);
diff --git a/src/isdb/Rescale.cpp b/src/isdb/Rescale.cpp
index f28dce8b53106f3b4a384c16f6c5e9fb53cea03d..0b9c0942cd51a810aa942657d05729a4df6db2da 100644
--- a/src/isdb/Rescale.cpp
+++ b/src/isdb/Rescale.cpp
@@ -310,13 +310,13 @@ Rescale::~Rescale()
 
 void Rescale::read_bias()
 {
-  double MDtime;
 // open file
   IFile *ifile = new IFile();
   ifile->link(*this);
   if(ifile->FileExist(Biasfilename_)) {
     ifile->open(Biasfilename_);
     // read all the lines, store last value of bias
+    double MDtime;
     while(ifile->scanField("MD_time",MDtime)) {
       for(unsigned i=0; i<bias_.size(); ++i) {
         // convert i to string
@@ -372,7 +372,6 @@ bool Rescale::doAccept(double oldE, double newE)
 void Rescale::doMonteCarlo(unsigned igamma, double oldE,
                            vector<double> args, vector<double> bargs)
 {
-  bool accept;
   double oldB, newB;
 
 // cycle on MC steps
@@ -395,7 +394,7 @@ void Rescale::doMonteCarlo(unsigned igamma, double oldE,
       newB = bias_[new_igamma];
     }
     // accept or reject
-    accept = doAccept(oldE+oldB, newE+newB);
+    bool accept = doAccept(oldE+oldB, newE+newB);
     if(accept) {
       igamma = new_igamma;
       oldE = newE;
diff --git a/src/multicolvar/CoordinationNumbers.cpp b/src/multicolvar/CoordinationNumbers.cpp
index 8a02e2e73f8839eed7c19561879a3d3d1000e989..5615c45001b36314137a6aded71f98f60ca6f95b 100644
--- a/src/multicolvar/CoordinationNumbers.cpp
+++ b/src/multicolvar/CoordinationNumbers.cpp
@@ -157,9 +157,10 @@ CoordinationNumbers::CoordinationNumbers(const ActionOptions&ao):
 
 double CoordinationNumbers::compute( const unsigned& tindex, AtomValuePack& myatoms ) const {
   // Calculate the coordination number
-  double dfunc, d2, sw, d, raised;
+  double dfunc, sw, d, raised;
   for(unsigned i=1; i<myatoms.getNumberOfAtoms(); ++i) {
     Vector& distance=myatoms.getPosition(i);
+    double d2;
     if ( (d2=distance[0]*distance[0])<rcut2 &&
          (d2+=distance[1]*distance[1])<rcut2 &&
          (d2+=distance[2]*distance[2])<rcut2 &&
diff --git a/src/multicolvar/DistanceFromContour.cpp b/src/multicolvar/DistanceFromContour.cpp
index 6f99e214a478ff53c3f3c5fea9ed3a059e09cec0..454a93389c375629c8df32caa515561ee77bdddd 100644
--- a/src/multicolvar/DistanceFromContour.cpp
+++ b/src/multicolvar/DistanceFromContour.cpp
@@ -206,9 +206,10 @@ void DistanceFromContour::calculate() {
   // Set bracket as center of mass of membrane in active region
   deactivateAllTasks();
   Vector myvec = getSeparation( getPosition(getNumberOfAtoms()-1), getPosition(0) ); pos2[dir]=myvec[dir];
-  taskFlags[0]=1; double d2, mindist = myvec.modulo2();
+  taskFlags[0]=1; double mindist = myvec.modulo2();
   for(unsigned j=1; j<getNumberOfAtoms()-1; ++j) {
     Vector distance=getSeparation( getPosition(getNumberOfAtoms()-1), getPosition(j) );
+    double d2;
     if( (d2=distance[perp_dirs[0]]*distance[perp_dirs[0]])<rcut2 &&
         (d2+=distance[perp_dirs[1]]*distance[perp_dirs[1]])<rcut2 ) {
       d2+=distance[dir]*distance[dir];
diff --git a/src/multicolvar/Distances.cpp b/src/multicolvar/Distances.cpp
index 579668b8807085dc092ac1db6171b4abd2aa00c2..561dd82cc8a738d93a99dbaf7b9cf10f02ec4c04 100644
--- a/src/multicolvar/Distances.cpp
+++ b/src/multicolvar/Distances.cpp
@@ -167,8 +167,8 @@ Distances::Distances(const ActionOptions&ao):
   checkRead();
 
   // Now check if we can use link cells
-  bool use_link=false; double rcut;
   if( getNumberOfVessels()>0 ) {
+    bool use_link=false; double rcut;
     vesselbase::LessThan* lt=dynamic_cast<vesselbase::LessThan*>( getPntrToVessel(0) );
     if( lt ) {
       use_link=true; rcut=lt->getCutoff();
diff --git a/src/multicolvar/InPlaneDistances.cpp b/src/multicolvar/InPlaneDistances.cpp
index ef9f4a55f52d68932aec143af01146c508050e2f..14ab35dd587e457259c33236664c7f87e7a714aa 100644
--- a/src/multicolvar/InPlaneDistances.cpp
+++ b/src/multicolvar/InPlaneDistances.cpp
@@ -100,8 +100,8 @@ InPlaneDistances::InPlaneDistances(const ActionOptions&ao):
   checkRead();
 
 // Now check if we can use link cells
-  bool use_link=false; double rcut;
   if( getNumberOfVessels()>0 ) {
+    bool use_link=false; double rcut;
     vesselbase::LessThan* lt=dynamic_cast<vesselbase::LessThan*>( getPntrToVessel(0) );
     if( lt ) {
       use_link=true; rcut=lt->getCutoff();
diff --git a/src/multicolvar/LocalAverage.cpp b/src/multicolvar/LocalAverage.cpp
index f99dcd7be5f10b8ae349bce2e127d7a0a1811553..659c45a23393417112a90b1f5219186f681f4b67 100644
--- a/src/multicolvar/LocalAverage.cpp
+++ b/src/multicolvar/LocalAverage.cpp
@@ -147,7 +147,7 @@ unsigned LocalAverage::getNumberOfQuantities() const {
 }
 
 double LocalAverage::compute( const unsigned& tindex, AtomValuePack& myatoms ) const {
-  double d2, sw, dfunc; MultiValue& myvals = myatoms.getUnderlyingMultiValue();
+  double sw, dfunc; MultiValue& myvals = myatoms.getUnderlyingMultiValue();
   std::vector<double> values( getBaseMultiColvar(0)->getNumberOfQuantities() );
 
   getInputData( 0, false, myatoms, values );
@@ -216,6 +216,7 @@ double LocalAverage::compute( const unsigned& tindex, AtomValuePack& myatoms ) c
 
   for(unsigned i=1; i<myatoms.getNumberOfAtoms(); ++i) {
     Vector& distance=myatoms.getPosition(i);  // getSeparation( myatoms.getPosition(0), myatoms.getPosition(i) );
+    double d2;
     if ( (d2=distance[0]*distance[0])<rcut2 &&
          (d2+=distance[1]*distance[1])<rcut2 &&
          (d2+=distance[2]*distance[2])<rcut2 &&
diff --git a/src/reference/ReferenceArguments.cpp b/src/reference/ReferenceArguments.cpp
index bea11a78490c09cae6dc2c776d6535728dfb5a22..ee3a1f71205148c095f4fccb04b185184bb5fad8 100644
--- a/src/reference/ReferenceArguments.cpp
+++ b/src/reference/ReferenceArguments.cpp
@@ -109,11 +109,11 @@ void ReferenceArguments::getArgumentRequests( std::vector<std::string>& argout,
       if( arg_names.size()!=argout.size() ) error("mismatched numbers of arguments in pdb frames");
     }
     for(unsigned i=0; i<arg_names.size(); ++i) {
-      bool found=false;
       if(!disable_checks) {
         if( argout[i]!=arg_names[i] ) error("found mismatched arguments in pdb frames");
         arg_der_index[i]=i;
       } else {
+        bool found=false;
         for(unsigned j=0; j<arg_names.size(); ++j) {
           if( argout[j]==arg_names[i] ) { found=true; arg_der_index[i]=j; break; }
         }
diff --git a/src/reference/ReferenceAtoms.cpp b/src/reference/ReferenceAtoms.cpp
index 6ba21f1e03cb8ec5554f50dd23b90a9395c958c0..2c8cb0d258047db7ddd97a8a0563853409e25a6c 100644
--- a/src/reference/ReferenceAtoms.cpp
+++ b/src/reference/ReferenceAtoms.cpp
@@ -99,9 +99,8 @@ void ReferenceAtoms::singleDomainRequests( std::vector<AtomNumber>& numbers, boo
       if( numbers.size()!=indices.size() ) error("mismatched numbers of atoms in pdb frames");
     }
 
-    bool found;
     for(unsigned i=0; i<indices.size(); ++i) {
-      found=false;
+      bool found=false;
       if(!disable_checks) {
         if( indices[i]!=numbers[i] ) error("found mismatched reference atoms in pdb frames");
         atom_der_index[i]=i;
diff --git a/src/secondarystructure/AlphaRMSD.cpp b/src/secondarystructure/AlphaRMSD.cpp
index 643f4cb5e24068a7604c8f70866d2d5706412092..873d6b15a32e786c4a7a3417070ce71c408d87e9 100644
--- a/src/secondarystructure/AlphaRMSD.cpp
+++ b/src/secondarystructure/AlphaRMSD.cpp
@@ -104,10 +104,10 @@ AlphaRMSD::AlphaRMSD(const ActionOptions&ao):
   std::vector<unsigned> chains; readBackboneAtoms( "protein", chains);
 
   // This constructs all conceivable sections of alpha helix in the backbone of the chains
-  unsigned nres, nprevious=0; std::vector<unsigned> nlist(30);
+  unsigned nprevious=0; std::vector<unsigned> nlist(30);
   for(unsigned i=0; i<chains.size(); ++i) {
     if( chains[i]<30 ) error("segment of backbone defined is not long enough to form an alpha helix. Each backbone fragment must contain a minimum of 6 residues");
-    nres=chains[i]/5;
+    unsigned nres=chains[i]/5;
     if( chains[i]%5!=0 ) error("backbone segment received does not contain a multiple of five residues");
     for(unsigned ires=0; ires<nres-5; ires++) {
       unsigned accum=nprevious + 5*ires;
diff --git a/src/secondarystructure/AntibetaRMSD.cpp b/src/secondarystructure/AntibetaRMSD.cpp
index fe843bd755b33a719a11f37301aba1153a075c46..528fa87bb3e69ca5fb10b351f6bbbd49091bd080 100644
--- a/src/secondarystructure/AntibetaRMSD.cpp
+++ b/src/secondarystructure/AntibetaRMSD.cpp
@@ -126,11 +126,11 @@ AntibetaRMSD::AntibetaRMSD(const ActionOptions&ao):
 
   // This constructs all conceivable sections of antibeta sheet in the backbone of the chains
   if( intra_chain ) {
-    unsigned nres, nprevious=0; std::vector<unsigned> nlist(30);
+    unsigned nprevious=0; std::vector<unsigned> nlist(30);
     for(unsigned i=0; i<chains.size(); ++i) {
       if( chains[i]<40 ) error("segment of backbone is not long enough to form an antiparallel beta hairpin. Each backbone fragment must contain a minimum of 8 residues");
       // Loop over all possible triples in each 8 residue segment of protein
-      nres=chains[i]/5;
+      unsigned nres=chains[i]/5;
       if( chains[i]%5!=0 ) error("backbone segment received does not contain a multiple of five residues");
       for(unsigned ires=0; ires<nres-7; ires++) {
         for(unsigned jres=ires+7; jres<nres; jres++) {
@@ -146,15 +146,15 @@ AntibetaRMSD::AntibetaRMSD(const ActionOptions&ao):
   }
   if( inter_chain ) {
     if( chains.size()==1 && style!="all" ) error("there is only one chain defined so cannot use inter_chain option");
-    unsigned iprev,jprev,inres,jnres; std::vector<unsigned> nlist(30);
+    std::vector<unsigned> nlist(30);
     for(unsigned ichain=1; ichain<chains.size(); ++ichain) {
-      iprev=0; for(unsigned i=0; i<ichain; ++i) iprev+=chains[i];
-      inres=chains[ichain]/5;
+      unsigned iprev=0; for(unsigned i=0; i<ichain; ++i) iprev+=chains[i];
+      unsigned inres=chains[ichain]/5;
       if( chains[ichain]%5!=0 ) error("backbone segment received does not contain a multiple of five residues");
       for(unsigned ires=0; ires<inres-2; ++ires) {
         for(unsigned jchain=0; jchain<ichain; ++jchain) {
-          jprev=0; for(unsigned i=0; i<jchain; ++i) jprev+=chains[i];
-          jnres=chains[jchain]/5;
+          unsigned jprev=0; for(unsigned i=0; i<jchain; ++i) jprev+=chains[i];
+          unsigned jnres=chains[jchain]/5;
           if( chains[jchain]%5!=0 ) error("backbone segment received does not contain a multiple of five residues");
           for(unsigned jres=0; jres<jnres-2; ++jres) {
             for(unsigned k=0; k<15; ++k) {
diff --git a/src/secondarystructure/ParabetaRMSD.cpp b/src/secondarystructure/ParabetaRMSD.cpp
index 4329edd6ee6e70ca9886796536c4b04e0a6ccfe6..b7907fbb1bc0f1126add3eb64763d9095097e5fc 100644
--- a/src/secondarystructure/ParabetaRMSD.cpp
+++ b/src/secondarystructure/ParabetaRMSD.cpp
@@ -127,11 +127,11 @@ ParabetaRMSD::ParabetaRMSD(const ActionOptions&ao):
 
   // This constructs all conceivable sections of antibeta sheet in the backbone of the chains
   if( intra_chain ) {
-    unsigned nres, nprevious=0; std::vector<unsigned> nlist(30);
+    unsigned nprevious=0; std::vector<unsigned> nlist(30);
     for(unsigned i=0; i<chains.size(); ++i) {
       if( chains[i]<40 ) error("segment of backbone is not long enough to form an antiparallel beta hairpin. Each backbone fragment must contain a minimum of 8 residues");
       // Loop over all possible triples in each 8 residue segment of protein
-      nres=chains[i]/5;
+      unsigned nres=chains[i]/5;
       if( chains[i]%5!=0 ) error("backbone segment received does not contain a multiple of five residues");
       for(unsigned ires=0; ires<nres-8; ires++) {
         for(unsigned jres=ires+6; jres<nres-2; jres++) {
@@ -148,15 +148,15 @@ ParabetaRMSD::ParabetaRMSD(const ActionOptions&ao):
   // This constructs all conceivable sections of antibeta sheet that form between chains
   if( inter_chain ) {
     if( chains.size()==1 && style!="all" ) error("there is only one chain defined so cannot use inter_chain option");
-    unsigned iprev,jprev,inres,jnres; std::vector<unsigned> nlist(30);
+    std::vector<unsigned> nlist(30);
     for(unsigned ichain=1; ichain<chains.size(); ++ichain) {
-      iprev=0; for(unsigned i=0; i<ichain; ++i) iprev+=chains[i];
-      inres=chains[ichain]/5;
+      unsigned iprev=0; for(unsigned i=0; i<ichain; ++i) iprev+=chains[i];
+      unsigned inres=chains[ichain]/5;
       if( chains[ichain]%5!=0 ) error("backbone segment received does not contain a multiple of five residues");
       for(unsigned ires=0; ires<inres-2; ++ires) {
         for(unsigned jchain=0; jchain<ichain; ++jchain) {
-          jprev=0; for(unsigned i=0; i<jchain; ++i) jprev+=chains[i];
-          jnres=chains[jchain]/5;
+          unsigned jprev=0; for(unsigned i=0; i<jchain; ++i) jprev+=chains[i];
+          unsigned jnres=chains[jchain]/5;
           if( chains[jchain]%5!=0 ) error("backbone segment received does not contain a multiple of five residues");
           for(unsigned jres=0; jres<jnres-2; ++jres) {
             for(unsigned k=0; k<15; ++k) {
diff --git a/src/tools/HistogramBead.cpp b/src/tools/HistogramBead.cpp
index 9c97a6033b0251dc9a9777dee4b0dd7334593053..0124165787959928475a4b8202e09edfbf90e963 100644
--- a/src/tools/HistogramBead.cpp
+++ b/src/tools/HistogramBead.cpp
@@ -229,9 +229,8 @@ double HistogramBead::calculateWithCutoff( double x, double& df ) const {
 }
 
 double HistogramBead::lboundDerivative( const double& x ) const {
-  double lowB;
   if( type==gaussian ) {
-    lowB = difference( x, lowb ) / ( sqrt(2.0) * width );
+    double lowB = difference( x, lowb ) / ( sqrt(2.0) * width );
     return exp( -lowB*lowB ) / ( sqrt(2*pi)*width );
   } else if ( type==triangular ) {
     plumed_error();
@@ -246,9 +245,8 @@ double HistogramBead::lboundDerivative( const double& x ) const {
 
 double HistogramBead::uboundDerivative( const double& x ) const {
   plumed_dbg_assert(init && periodicity!=unset );
-  double upperB;
   if( type==gaussian ) {
-    upperB = difference( x, highb ) / ( sqrt(2.0) * width );
+    double upperB = difference( x, highb ) / ( sqrt(2.0) * width );
     return exp( -upperB*upperB ) / ( sqrt(2*pi)*width );
   } else if ( type==triangular ) {
     plumed_error();
diff --git a/src/vesselbase/Moments.cpp b/src/vesselbase/Moments.cpp
index 88759aef95610648ccdb4dd8891fc0216a3e4b1a..17e5fe498de86e48d0e4c07d81d717b10bf44411 100644
--- a/src/vesselbase/Moments.cpp
+++ b/src/vesselbase/Moments.cpp
@@ -105,8 +105,8 @@ void Moments::finish( const std::vector<double>& buffer ) {
     std::string str_min, str_max; getAction()->retrieveDomain( str_min, str_max );
     double pfactor, min, max; Tools::convert(str_min,min); Tools::convert(str_max,max);
     pfactor = 2*pi / ( max-min ); myvalue.setDomain( str_min, str_max );
-    double sinsum=0, cossum=0, val;
-    for(unsigned i=0; i<nvals; ++i) { val=pfactor*( buffer[bufstart + i*nspace*vecsize+nspace] - min ); sinsum+=sin(val); cossum+=cos(val); }
+    double sinsum=0, cossum=0;
+    for(unsigned i=0; i<nvals; ++i) { double val=pfactor*( buffer[bufstart + i*nspace*vecsize+nspace] - min ); sinsum+=sin(val); cossum+=cos(val); }
     mean = 0.5 + atan2( sinsum / static_cast<double>( nvals ), cossum / static_cast<double>( nvals ) ) / (2*pi);
     mean = min + (max-min)*mean;
   } else {