diff --git a/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C b/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C
index ada7d06b5bc5df1e0b255187576be016ddb0e175..64346e1d25f16747d2f5a6cc0e0c087f9fc53c7b 100644
--- a/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C
+++ b/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -2560,6 +2560,11 @@ Foam::labelBits Foam::indexedOctree<Type>::findNode
 template<class Type>
 Foam::label Foam::indexedOctree<Type>::findInside(const point& sample) const
 {
+    if (nodes_.empty())
+    {
+        return -1;
+    }
+
     labelBits index = findNode(0, sample);
 
     const node& nod = nodes_[getNode(index)];
@@ -2592,6 +2597,11 @@ const Foam::labelList& Foam::indexedOctree<Type>::findIndices
     const point& sample
 ) const
 {
+    if (nodes_.empty())
+    {
+        return emptyList<label>();
+    }
+
     labelBits index = findNode(0, sample);
 
     const node& nod = nodes_[getNode(index)];
@@ -2603,10 +2613,8 @@ const Foam::labelList& Foam::indexedOctree<Type>::findIndices
     {
         return contents_[getContent(contentIndex)];
     }
-    else
-    {
-        return emptyList<label>();
-    }
+
+    return emptyList<label>();
 }
 
 
@@ -2688,18 +2696,21 @@ void Foam::indexedOctree<Type>::findNear
     CompareOp& cop
 ) const
 {
-    findNear
-    (
-        nearDist,
-        true,
-        *this,
-        nodePlusOctant(0, 0),
-        bb(),
-        tree2,
-        nodePlusOctant(0, 0),
-        tree2.bb(),
-        cop
-    );
+    if (!nodes_.empty())
+    {
+        findNear
+        (
+            nearDist,
+            true,
+            *this,
+            nodePlusOctant(0, 0),
+            bb(),
+            tree2,
+            nodePlusOctant(0, 0),
+            tree2.bb(),
+            cop
+        );
+    }
 }
 
 
@@ -2711,6 +2722,11 @@ void Foam::indexedOctree<Type>::print
     const label nodeI
 ) const
 {
+    if (nodes_.empty())
+    {
+        return;
+    }
+
     const node& nod = nodes_[nodeI];
     const treeBoundBox& bb = nod.bb_;
 
diff --git a/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/externalWallHeatFluxTemperature/externalWallHeatFluxTemperatureFvPatchScalarField.C b/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/externalWallHeatFluxTemperature/externalWallHeatFluxTemperatureFvPatchScalarField.C
index dbd129117204d0de9d7e81368fd210348d9a69b5..99ab2d9e55da0d60c427f82724d381aa4c337952 100644
--- a/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/externalWallHeatFluxTemperature/externalWallHeatFluxTemperatureFvPatchScalarField.C
+++ b/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/externalWallHeatFluxTemperature/externalWallHeatFluxTemperatureFvPatchScalarField.C
@@ -58,6 +58,8 @@ externalWallHeatFluxTemperatureFvPatchScalarField
     temperatureCoupledBase(patch(), "undefined", "undefined", "undefined-K"),
     mode_(fixedHeatFlux),
     Q_(0),
+    q_(),
+    h_(),
     Ta_(),
     relaxation_(1),
     emissivity_(0),
@@ -84,7 +86,9 @@ externalWallHeatFluxTemperatureFvPatchScalarField
     temperatureCoupledBase(patch(), dict),
     mode_(operationModeNames.lookup("mode", dict)),
     Q_(0),
-    Ta_(Function1<scalar>::New("Ta", dict)),
+    q_(),
+    h_(),
+    Ta_(),
     relaxation_(dict.lookupOrDefault<scalar>("relaxation", 1)),
     emissivity_(dict.lookupOrDefault<scalar>("emissivity", 0)),
     qrRelaxation_(dict.lookupOrDefault<scalar>("qrRelaxation", 1)),
@@ -109,6 +113,7 @@ externalWallHeatFluxTemperatureFvPatchScalarField
         case fixedHeatTransferCoeff:
         {
             h_ = scalarField("h", dict, p.size());
+            Ta_ = Function1<scalar>::New("Ta", dict);
 
             if (dict.found("thicknessLayers"))
             {
@@ -175,12 +180,12 @@ externalWallHeatFluxTemperatureFvPatchScalarField
     temperatureCoupledBase(patch(), ptf),
     mode_(ptf.mode_),
     Q_(ptf.Q_),
-    q_(ptf.q_, mapper),
-    h_(ptf.h_, mapper),
+    q_(),
+    h_(),
     Ta_(ptf.Ta_, false),
     relaxation_(ptf.relaxation_),
     emissivity_(ptf.emissivity_),
-    qrPrevious_(ptf.qrPrevious_, mapper),
+    qrPrevious_(),
     qrRelaxation_(ptf.qrRelaxation_),
     qrName_(ptf.qrName_),
     thicknessLayers_(ptf.thicknessLayers_),
@@ -194,12 +199,14 @@ externalWallHeatFluxTemperatureFvPatchScalarField
         }
         case fixedHeatFlux:
         {
+            q_.setSize(mapper.size());
             q_.map(ptf.q_, mapper);
 
             break;
         }
         case fixedHeatTransferCoeff:
         {
+            h_.setSize(mapper.size());
             h_.map(ptf.h_, mapper);
 
             break;
diff --git a/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoAdvection/isoAdvection.C b/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoAdvection/isoAdvection.C
index e039b0b5724cb174a215e3d7e4d6fbee9709c765..d149e0c5ef62b1b9163828690b19c716fecee7c2 100644
--- a/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoAdvection/isoAdvection.C
+++ b/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoAdvection/isoAdvection.C
@@ -615,8 +615,8 @@ void Foam::isoAdvection::limitFluxes()
     const scalar aTol = 1.0e-12;          // Note: tolerances
     const scalar maxAlphaMinus1 = 1;      // max(alphaNew - 1);
     const scalar minAlpha = -1;           // min(alphaNew);
-    const label nUndershoots = 20;        // sum(neg(alphaNew + aTol));
-    const label nOvershoots = 20;         // sum(pos(alphaNew - 1 - aTol));
+    const label nUndershoots = 20;        // sum(neg0(alphaNew + aTol));
+    const label nOvershoots = 20;         // sum(pos0(alphaNew - 1 - aTol));
     cellIsBounded_ = false;
 
     // Loop number of bounding steps
@@ -682,8 +682,8 @@ void Foam::isoAdvection::limitFluxes()
             scalarField alphaNew(alpha1In_ - fvc::surfaceIntegrate(dVf_)());
             label maxAlphaMinus1 = max(alphaNew - 1);
             scalar minAlpha = min(alphaNew);
-            label nUndershoots = sum(neg(alphaNew + aTol));
-            label nOvershoots = sum(pos(alphaNew - 1 - aTol));
+            label nUndershoots = sum(neg0(alphaNew + aTol));
+            label nOvershoots = sum(pos0(alphaNew - 1 - aTol));
             Info<< "After bounding number " << n + 1 << " of time "
                 << mesh_.time().value() << ":" << endl;
             Info<< "nOvershoots = " << nOvershoots << " with max(alphaNew-1) = "
@@ -792,7 +792,7 @@ void Foam::isoAdvection::boundFromAbove
                         fluidToPassOn*mag(phi[fi]*dt)/dVftot;
 
                     nFacesToPassFluidThrough +=
-                        pos(dVfmax[fi] - fluidToPassThroughFace);
+                        pos0(dVfmax[fi] - fluidToPassThroughFace);
 
                     fluidToPassThroughFace =
                         min(fluidToPassThroughFace, dVfmax[fi]);
@@ -1014,9 +1014,9 @@ void Foam::isoAdvection::applyBruteForceBounding()
     {
         alpha1_ =
             alpha1_
-           *pos(alpha1_ - snapAlphaTol)
-           *neg(alpha1_ - (1.0 - snapAlphaTol))
-          + pos(alpha1_ - (1.0 - snapAlphaTol));
+           *pos0(alpha1_ - snapAlphaTol)
+           *neg0(alpha1_ - (1.0 - snapAlphaTol))
+          + pos0(alpha1_ - (1.0 - snapAlphaTol));
 
         alpha1Changed = true;
     }
diff --git a/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoCutFace/isoCutFace.C b/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoCutFace/isoCutFace.C
index 33d4e7f412c241a3dccf19b8ec37404ac4b9b36f..83292012a0db560d7ebcaefa19a4054cde784c83 100644
--- a/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoCutFace/isoCutFace.C
+++ b/src/finiteVolume/fvMatrices/solvers/isoAdvection/isoCutFace/isoCutFace.C
@@ -362,7 +362,7 @@ Foam::scalar Foam::isoCutFace::timeIntegratedArea
     {
         // If all face cuttings were in the past and cell is filling up (Un0>0)
         // then face must be full during whole time interval
-        tIntArea = magSf*dt*pos(Un0);
+        tIntArea = magSf*dt*pos0(Un0);
         return tIntArea;
     }
 
@@ -373,7 +373,7 @@ Foam::scalar Foam::isoCutFace::timeIntegratedArea
         // If all cuttings are in the future but non of them within [0,dt] then
         // if cell is filling up (Un0 > 0) face must be empty during whole time
         // interval
-        tIntArea = magSf*dt*(1 - pos(Un0));
+        tIntArea = magSf*dt*(1 - pos0(Un0));
         return tIntArea;
     }
 
@@ -398,7 +398,7 @@ Foam::scalar Foam::isoCutFace::timeIntegratedArea
         // If Un0 > 0 cell is filling up and it must initially be empty.
         // If Un0 < 0 cell must initially be full(y immersed in fluid A).
         time = firstTime;
-        initialArea = magSf*(1.0 - pos(Un0));
+        initialArea = magSf*(1.0 - pos0(Un0));
         tIntArea = initialArea*time;
         cutPoints(fPts, pTimes, time, FIIL);
     }
@@ -470,7 +470,7 @@ Foam::scalar Foam::isoCutFace::timeIntegratedArea
     {
         // FIIL will leave the face at lastTime and face will be fully in fluid
         // A or fluid B in the time interval from lastTime to dt.
-        tIntArea += magSf*(dt - lastTime)*pos(Un0);
+        tIntArea += magSf*(dt - lastTime)*pos0(Un0);
     }
 
     return tIntArea;
diff --git a/src/lagrangian/distributionModels/binned/binned.C b/src/lagrangian/distributionModels/binned/binned.C
index 57530fa649c794e4552ac5b06e7f04e2bba4ab7b..a5cf7e1f2b632fc9f86abbafa09a0671f65287aa 100644
--- a/src/lagrangian/distributionModels/binned/binned.C
+++ b/src/lagrangian/distributionModels/binned/binned.C
@@ -47,10 +47,6 @@ const char* Foam::distributionModels::binned::header =
 void Foam::distributionModels::binned::initialise()
 {
     const label nSample(xy_.size());
-    forAll(xy_, bini)
-    {
-        xy_[bini][1] /= scalar(nSample);
-    }
 
     // Convert values to integral values
     for (label bini = 1; bini < nSample; ++bini)
@@ -58,6 +54,13 @@ void Foam::distributionModels::binned::initialise()
         xy_[bini][1] += xy_[bini - 1][1];
     }
 
+    // Normalise
+    scalar sumProb = xy_.last()[1];
+    forAll(xy_, bini)
+    {
+        xy_[bini][1] /= sumProb;
+    }
+
     // Calculate the mean value
     label bini = 0;
     forAll(xy_, i)
@@ -188,16 +191,7 @@ Foam::scalar Foam::distributionModels::binned::sample() const
     {
         if (xy_[i][1] > y)
         {
-            scalar d1 = y - xy_[i][1];
-            scalar d2 = xy_[i+1][1] - y;
-            if (d1 < d2)
-            {
-                return xy_[i][0];
-            }
-            else
-            {
-                return xy_[i+1][0];
-            }
+            return xy_[i][0];
         }
     }
 
diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C
index 299e9a5333ddca126930a8774f1e2d8198bcecb0..e86bcc7962126ea65251d1feb0a3734c3d255501 100644
--- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C
@@ -312,7 +312,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
     const pointField& pointLst = surf.points();
     const UList<Face>& faceLst = surf.surfFaces();
 
-    const UList<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().size()
       ? surf.surfZones()
@@ -393,7 +393,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
 
     if (zoneLst.size() <= 1)
     {
-        const List<surfZone>& zones =
+        const surfZoneList zones =
         (
             zoneLst.size()
           ? zoneLst
diff --git a/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.C b/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.C
index b834b4ae5f10f4c861743c5e76583915551cf56a..7225a47cc4c7a0931117b620782e5fea6df4494f 100644
--- a/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/fire/FLMAsurfaceFormat.C
@@ -169,7 +169,7 @@ void Foam::fileFormats::FLMAsurfaceFormat<Face>::write
     const UList<label>& faceMap = surf.faceMap();
 
     // for no zones, suppress the group name
-    const List<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().empty()
       ? surfaceFormatsCore::oneZone(faceLst, word::null)
diff --git a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C
index 352babafbb5adcffe8f5639c57bd7e912eec49db..ca460aa0192789abadd1b9816e1396299aebce92 100644
--- a/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/gts/GTSsurfaceFormat.C
@@ -253,7 +253,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
     const UList<point>& pointLst = surf.points();
     const UList<Face>& faceLst  = surf.surfFaces();
 
-    const UList<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().size()
       ? surf.surfZones()
diff --git a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C
index 03e66e3c75f8d55db3b8e7732a9d041a5bf8a09e..503616989c89b6a8cfe4dc706313cb5e2cb7bfc6 100644
--- a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C
@@ -420,7 +420,7 @@ void Foam::fileFormats::NASsurfaceFormat<Face>::write
     const UList<label>& faceMap  = surf.faceMap();
 
     // for no zones, suppress the group name
-    const UList<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().empty()
       ? surfaceFormatsCore::oneZone(faceLst, "")
diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C
index 77128da7cae93b575ca3cadc634ae72c718dffb3..c2897bbac84b152e0b5ca2fce88817ed423ba433 100644
--- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C
@@ -217,7 +217,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
     const UList<label>& faceMap  = surf.faceMap();
 
     // for no zones, suppress the group name
-    const UList<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().empty()
       ? surfaceFormatsCore::oneZone(faceLst, "")
diff --git a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C
index 5f54451022eea533e2e53b29f38bee8ffc02c762..04552eb7131c91d8dafb247246d93174cbcaef16 100644
--- a/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/smesh/SMESHsurfaceFormat.C
@@ -41,7 +41,7 @@ void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
     const UList<Face>&  faceLst  = surf.surfFaces();
     const UList<label>& faceMap  = surf.faceMap();
 
-    const UList<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().empty()
       ? surfaceFormatsCore::oneZone(faceLst)
diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C
index b9f3f92afaabd0c24ee6ca9514567feba7373679..cc61fa0f296d352361361d130b6ec02ac04efe3d 100644
--- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormat.C
@@ -241,7 +241,7 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
     const UList<Face>&  faceLst  = surf.surfFaces();
     const UList<label>& faceMap  = surf.faceMap();
 
-    const UList<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().empty()
       ? surfaceFormatsCore::oneZone(faceLst)
diff --git a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C
index 64ad423df8943295bfa99b8dd5e50621af089145..4026f85e83d2a43365e90c2a4168997318e825b7 100644
--- a/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/stl/STLsurfaceFormat.C
@@ -215,7 +215,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii
     const UList<Face>&   faceLst = surf.surfFaces();
     const UList<label>&  faceMap = surf.faceMap();
 
-    const UList<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().empty()
       ? surfaceFormatsCore::oneZone(faceLst)
@@ -269,7 +269,7 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary
     const UList<Face>&   faceLst = surf.surfFaces();
     const UList<label>&  faceMap = surf.faceMap();
 
-    const UList<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().size() > 1
       ? surf.surfZones()
diff --git a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C
index 898adcb833e1baa4fbe2b91522613b0c65884390..a3b2046d27a124e364928ee9426779d155b5accd 100644
--- a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormat.C
@@ -161,7 +161,7 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write
     const UList<Face>&   faceLst = surf.surfFaces();
     const UList<label>&  faceMap = surf.faceMap();
 
-    const UList<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().empty()
       ? surfaceFormatsCore::oneZone(faceLst)
diff --git a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C
index f75920ae9a127b16120cdad941d8235212a1d6db..1bb3d3cdafcf5392f715b87d990584bc582cec6d 100644
--- a/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/vtk/VTKsurfaceFormat.C
@@ -265,7 +265,7 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
     const UList<Face>&   faceLst = surf.surfFaces();
     const UList<label>&  faceMap = surf.faceMap();
 
-    const UList<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().empty()
       ? surfaceFormatsCore::oneZone(faceLst)
diff --git a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.C b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.C
index bf3d09911a3c913d90f41754d9f75f7efc388c57..c1f22611bd8a87dbf68f8ec0cb9fc933319d46cd 100644
--- a/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/vtp/VTPsurfaceFormat.C
@@ -118,7 +118,7 @@ void Foam::fileFormats::VTPsurfaceFormat<Face>::write
     const UList<Face>&   faceLst = surf.surfFaces();
     const UList<label>&  faceMap = surf.faceMap();
 
-    const List<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().empty()
       ? surfaceFormatsCore::oneZone(faceLst)
diff --git a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C
index fc02e1a085e2506d7dbf759bbe2af8f072aa3caf..03aee4006a8b7d8ff6745f4941254d463b0d9c11 100644
--- a/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/x3d/X3DsurfaceFormat.C
@@ -41,7 +41,7 @@ void Foam::fileFormats::X3DsurfaceFormat<Face>::write
     const UList<label>&  faceMap = surf.faceMap();
 
     // for no zones, suppress the group name
-    const UList<surfZone>& zones =
+    const surfZoneList zones =
     (
         surf.surfZones().empty()
       ? surfaceFormatsCore::oneZone(faceLst, word::null)