diff --git a/doc/changes/onTheFly.txt b/doc/changes/onTheFly.txt
index 9734c1f5a8d5e792d3d674770b7e362bd5280974..2dc3f5edfaf99bb39b6bd0f80c84254a62cae228 100644
--- a/doc/changes/onTheFly.txt
+++ b/doc/changes/onTheFly.txt
@@ -49,7 +49,7 @@ Example: Look up dictionary entries and do some calculation
 code, codeInclude, codeOptions sections (these are just strings) and
 calculates the SHA1 checksum of the contents.
 - it copies a template file
-($FOAM_CODESTREAM_TEMPLATE_DIR/codeStreamTemplate.C), substituting all
+($FOAM_CODESTREAM_TEMPLATES/codeStreamTemplate.C), substituting all
 occurences of code, codeInclude, codeOptions.
 - it writes library source files to constant/codeStream/<sha1> and compiles it
 using 'wmake libso'.
diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C
index 155fcea58dbcb0fe035a346fe72a6046d6b8c8f0..03eefb623b053fbf4ce6b9ce42a66e6365d0d3c4 100644
--- a/src/OSspecific/POSIX/POSIX.C
+++ b/src/OSspecific/POSIX/POSIX.C
@@ -102,7 +102,7 @@ Foam::string Foam::getEnv(const word& envName)
 bool Foam::setEnv
 (
     const word& envName,
-    const string& value,
+    const std::string& value,
     const bool overwrite
 )
 {
@@ -1066,7 +1066,7 @@ bool Foam::ping(const word& hostname, const label timeOut)
 }
 
 
-int Foam::system(const string& command)
+int Foam::system(const std::string& command)
 {
     return ::system(command.c_str());
 }
@@ -1084,14 +1084,14 @@ bool Foam::dlClose(void* handle)
 }
 
 
-void* Foam::dlSym(void* handle, const string& symbol)
+void* Foam::dlSym(void* handle, const std::string& symbol)
 {
     void* fun = dlsym(handle, symbol.c_str());
 
     char *error;
     if ((error = dlerror()) != NULL)
     {
-        WarningIn("dlSym(void*, const string&)")
+        WarningIn("dlSym(void*, const std::string&)")
             << "Cannot lookup symbol " << symbol << " : " << error
             << endl;
     }
diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
index 5a2735541065443af08a4b50010e0b6a0d9c511f..5eb948eee1eb6626f321fd4b4ac4148be2ef1214 100644
--- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
+++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
@@ -57,15 +57,9 @@ namespace functionEntries
 }
 
 
-const Foam::word Foam::functionEntries::codeStream::codeTemplateName
+const Foam::word Foam::functionEntries::codeStream::codeTemplateC
     = "codeStreamTemplate.C";
 
-const Foam::word Foam::functionEntries::codeStream::codeTemplateEnvName
-    = "FOAM_CODESTREAM_TEMPLATES";
-
-const Foam::fileName Foam::functionEntries::codeStream::codeTemplateDirName
-    = "codeTemplates/codeStream";
-
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
@@ -148,49 +142,30 @@ bool Foam::functionEntries::codeStream::execute
             {
                 Info<< "Creating new library in " << libPath << endl;
 
-                fileName srcFile;
-
-                // try to get template from FOAM_CODESTREAM_TEMPLATES
-                fileName templateDir
+                const fileName fileCsrc
                 (
-                    Foam::getEnv(codeTemplateEnvName)
-                );
-
-                if (!templateDir.empty())
-                {
-                    srcFile = templateDir/codeTemplateName;
-                    if (!isFile(srcFile, false))
-                    {
-                        srcFile.clear();
-                    }
-                }
-
-                // not found - fallback to ~OpenFOAM expansion
-                if (srcFile.empty())
-                {
-                    srcFile = findEtcFile
+                    codeStreamTools::findTemplate
                     (
-                        codeTemplateDirName/codeTemplateName
-                    );
-                }
+                        codeTemplateC
+                    )
+                );
 
-                if (srcFile.empty())
+                // not found!
+                if (fileCsrc.empty())
                 {
                     FatalIOErrorIn
                     (
                         "functionEntries::codeStream::execute(..)",
                         parentDict
                     )   << "Could not find the code template: "
-                        << codeTemplateName << nl
-                        << "Under the $FOAM_CODESTREAM_TEMPLATES directory"
-                        << " via via the ~OpenFOAM/" / codeTemplateDirName
-                        << " expansion"
+                        << codeTemplateC << nl
+                        << codeStreamTools::searchedLocations()
                         << exit(FatalIOError);
                 }
 
 
                 List<codeStreamTools::fileAndVars> copyFiles(1);
-                copyFiles[0].file() = srcFile;
+                copyFiles[0].file() = fileCsrc;
                 copyFiles[0].set("codeInclude", codeInclude);
                 copyFiles[0].set("code", code);
 
@@ -199,7 +174,7 @@ bool Foam::functionEntries::codeStream::execute
                 // Write Make/files
                 filesContents[0].first() = "Make/files";
                 filesContents[0].second() =
-                    codeTemplateName + "\n"
+                    codeTemplateC + "\n\n"
                     "LIB = $(FOAM_USER_LIBBIN)/lib" + name;
 
                 // Write Make/options
@@ -214,7 +189,7 @@ bool Foam::functionEntries::codeStream::execute
                     (
                         "functionEntries::codeStream::execute(..)",
                         parentDict
-                    )   << "Failed writing " << endl
+                    )   << "Failed writing " <<nl
                         << copyFiles << endl
                         << filesContents
                         << exit(FatalIOError);
diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H
index ea732167b5fd786d75a1587d18dc872db88c17ec..ecfbd1836a9cc9ab9f46fe32215b89b490ade855 100644
--- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H
+++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H
@@ -114,16 +114,8 @@ public:
 
     // Static data members
 
-        //- Name of the code template to be used
-        const static word codeTemplateName;
-
-        //- Name of the code template environment variable
-        //  Used to located the codeTemplateName
-        const static word codeTemplateEnvName;
-
-        //- Name of the code template sub-directory
-        //  Used when locating the codeTemplateName via Foam::findEtcFile
-        const static fileName codeTemplateDirName;
+        //- Name of the C code template to be used
+        const static word codeTemplateC;
 
 
     //- Runtime type information
diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C
index 783f986a0e028ebbfa1f0b3afd29775a928de062..1b7928ee3282a70dedb722616819ab2f1bc2e110 100644
--- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C
+++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.C
@@ -40,6 +40,53 @@ int Foam::codeStreamTools::allowSystemOperations
 );
 
 
+const Foam::word Foam::codeStreamTools::codeTemplateEnvName
+    = "FOAM_CODESTREAM_TEMPLATES";
+
+const Foam::fileName Foam::codeStreamTools::codeTemplateDirName
+    = "codeTemplates/codeStream";
+
+
+// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
+
+Foam::fileName Foam::codeStreamTools::findTemplate(const word& templateFile)
+{
+    // try to get template from FOAM_CODESTREAM_TEMPLATES
+    fileName templateDir(Foam::getEnv(codeTemplateEnvName));
+
+    fileName file;
+    if (!templateDir.empty() && isDir(templateDir))
+    {
+        file = templateDir/templateFile;
+        if (!isFile(file, false))
+        {
+            file.clear();
+        }
+    }
+
+    // not found - fallback to ~OpenFOAM expansion
+    if (file.empty())
+    {
+        file = findEtcFile(codeTemplateDirName/templateFile);
+    }
+
+    return file;
+}
+
+
+Foam::string Foam::codeStreamTools::searchedLocations()
+{
+    return
+    (
+        "Under the $"
+      + codeTemplateDirName
+      + " directory or via via the ~OpenFOAM/"
+      + codeTemplateDirName
+      + " expansion"
+    );
+}
+
+
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
 void Foam::codeStreamTools::copyAndExpand
diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H
index 0e989eafd67d05fdf3534a582a70398329bc4a5f..58f48cf6d08dc89937d63f43ee9defc4e828dfef 100644
--- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H
+++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStreamTools.H
@@ -109,7 +109,18 @@ protected:
 
 public:
 
-    static int allowSystemOperations;
+    // Static data members
+
+        //- Name of the code template environment variable
+        //  Used to located the codeTemplateName
+        const static word codeTemplateEnvName;
+
+        //- Name of the code template sub-directory
+        //  Used when locating the codeTemplateName via Foam::findEtcFile
+        const static fileName codeTemplateDirName;
+
+
+        static int allowSystemOperations;
 
     // Constructors
 
@@ -150,6 +161,15 @@ public:
 
         bool copyFilesContents(const fileName& dir) const;
 
+
+        //- Find a code-template via the codeTemplateEnvName
+        //  alternatively in the codeTemplateDirName via Foam::findEtcFile
+        static fileName findTemplate(const word& templateName);
+
+        //- List searched locations in a format suitable for display an error
+        static string searchedLocations();
+
+
         static void* findLibrary(const fileName& libPath);
 
         static bool writeDigest(const fileName& dir, const SHA1Digest& sha1);
diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H
index 7ad1bec12be95795986b33d50ffda34ce066d9b6..38b0d14a1082334743e6479b0b7d5ae2ee64bdf8 100644
--- a/src/OpenFOAM/include/OSspecific.H
+++ b/src/OpenFOAM/include/OSspecific.H
@@ -65,7 +65,7 @@ bool env(const word&);
 string getEnv(const word&);
 
 //- Set an environment variable
-bool setEnv(const word& name, const string& value, const bool overwrite);
+bool setEnv(const word& name, const std::string& value, const bool overwrite);
 
 //- Return the system's host name, as per hostname(1)
 //  Optionally with the full name (as per the '-f' option)
@@ -182,7 +182,7 @@ bool ping(const word&, const label port, const label timeOut);
 bool ping(const word&, const label timeOut=10);
 
 //- Execute the specified command
-int system(const string& command);
+int system(const std::string& command);
 
 //- open a shared library. Return handle to library
 void* dlOpen(const fileName& lib);
@@ -191,7 +191,7 @@ void* dlOpen(const fileName& lib);
 bool dlClose(void*);
 
 //- Lookup a symbol in a dlopened library using handle
-void* dlSym(void* handle, const string& symbol);
+void* dlSym(void* handle, const std::string& symbol);
 
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C
index d7f7c3594b62c72f161f45c1c0b40a67e5815d91..4525e6a3ae602eed3e7d71b0e75181754df64584 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.C
@@ -34,6 +34,16 @@ License
 #include "OFstream.H"
 #include "codeStreamTools.H"
 #include "codeProperties.H"
+#include "stringOps.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+const Foam::word Foam::codedFixedValueFvPatchScalarField::codeTemplateC
+    = "fixedValueFvPatchScalarFieldTemplate.C";
+
+const Foam::word Foam::codedFixedValueFvPatchScalarField::codeTemplateH
+    = "fixedValueFvPatchScalarFieldTemplate.H";
+
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
@@ -68,84 +78,101 @@ Foam::codedFixedValueFvPatchScalarField::dict() const
 
 void Foam::codedFixedValueFvPatchScalarField::writeLibrary
 (
-    const fileName dir,
-    const fileName libPath,
+    const fileName& dir,
+    const fileName& libPath,
     const dictionary& dict
 )
 {
-    Info<< "Creating new library in " << libPath << endl;
-
     // Write files for new library
-    if (Pstream::master())
+    if (!Pstream::master())
     {
-        fileName templates(Foam::getEnv("FOAM_CODESTREAM_TEMPLATE_DIR"));
-        if (!templates.size())
-        {
-            FatalIOErrorIn
-            (
-                "codedFixedValueFvPatchScalarField::writeLibrary(..)",
-                dict
-            )   << "Please set environment variable"
-                << " FOAM_CODESTREAM_TEMPLATE_DIR"
-                << " to point to the location of "
-                << "fixedValueFvPatchScalarFieldTemplate.C"
-                << exit(FatalIOError);
-        }
+        return;
+    }
 
+    // "codeInclude" is optional
+    string codeInclude;
+    if (dict.found("codeInclude"))
+    {
+        codeInclude = stringOps::trimLeft(dict["codeInclude"]);
+    }
 
-        // Extract sections of code
-        string codeInclude = "";
-        if (dict.found("codeInclude"))
-        {
-            codeInclude = codeStreamTools::stripLeading(dict["codeInclude"]);
-        }
-        string code = codeStreamTools::stripLeading(dict["code"]);
+    // "codeOptions" is optional
+    string codeOptions;
+    if (dict.found("codeOptions"))
+    {
+        codeOptions = stringOps::trimLeft(dict["codeOptions"]);
+    }
 
-        string codeOptions = "";
-        if (dict.found("codeOptions"))
-        {
-            codeOptions = codeStreamTools::stripLeading(dict["codeOptions"]);
-        }
+    // "code" is mandatory
+    string code = stringOps::trimLeft(dict["code"]);
 
 
-        List<fileAndVars> copyFiles(2);
-        copyFiles[0].first() =
-            templates/"fixedValueFvPatchScalarFieldTemplate.C";
+    Info<< "Creating new library in " << libPath << endl;
 
-        copyFiles[0].second().setSize(2);
-        copyFiles[0].second()[0] = Pair<string>("codeInclude", codeInclude);
-        copyFiles[0].second()[1] = Pair<string>("code", code);
+    const fileName fileCsrc
+    (
+        codeStreamTools::findTemplate
+        (
+            codeTemplateC
+        )
+    );
 
-        copyFiles[1].first() =
-            templates/"fixedValueFvPatchScalarFieldTemplate.H";
+    const fileName fileHsrc
+    (
+        codeStreamTools::findTemplate
+        (
+            codeTemplateH
+        )
+    );
 
+    if (fileCsrc.empty() || fileHsrc.empty())
+    {
+        FatalIOErrorIn
+        (
+            "codedFixedValueFvPatchScalarField::writeLibrary(..)",
+            dict
+        )   << "Could not find one or both code templates: "
+            << codeTemplateC << ", " << codeTemplateH << nl
+            << codeStreamTools::searchedLocations()
+            << exit(FatalIOError);
+    }
 
 
-        List<fileAndContent> filesContents(2);
-        // Write Make/files
-        filesContents[0].first() = "Make/files";
-        filesContents[0].second() =
-            "fixedValueFvPatchScalarFieldTemplate.C \n\n"
-            "LIB = $(FOAM_USER_LIBBIN)/lib" + redirectType_;
-        // Write Make/options
-        filesContents[1].first() = "Make/options";
-        filesContents[1].second() =
-            "EXE_INC = -g\\\n    -I$(LIB_SRC)/finiteVolume/lnInclude\\\n"
-          + codeOptions
-          + "\n\nLIB_LIBS = ";
 
-        codeStreamTools writer(redirectType_, copyFiles, filesContents);
-        if (!writer.copyFilesContents(dir))
-        {
-            FatalIOErrorIn
-            (
-                "codedFixedValueFvPatchScalarField::writeLibrary(..)",
-                dict
-            )   << "Failed writing " << endl
-                << copyFiles << endl
-                << filesContents
-                << exit(FatalIOError);
-        }
+    List<codeStreamTools::fileAndVars> copyFiles(2);
+    copyFiles[0].file() = fileCsrc;
+    copyFiles[0].set("codeInclude", codeInclude);
+    copyFiles[0].set("code", code);
+
+    copyFiles[1].file() = fileHsrc;
+
+
+    List<codeStreamTools::fileAndContent> filesContents(2);
+
+    // Write Make/files
+    filesContents[0].first() = "Make/files";
+    filesContents[0].second() =
+        codeTemplateC + "\n\n"
+        "LIB = $(FOAM_USER_LIBBIN)/lib" + redirectType_;
+
+    // Write Make/options
+    filesContents[1].first() = "Make/options";
+    filesContents[1].second() =
+        "EXE_INC = -g \\\n-I$(LIB_SRC)/finiteVolume/lnInclude\\\n"
+        + codeOptions
+        + "\n\nLIB_LIBS = ";
+
+    codeStreamTools writer(redirectType_, copyFiles, filesContents);
+    if (!writer.copyFilesContents(dir))
+    {
+        FatalIOErrorIn
+        (
+            "codedFixedValueFvPatchScalarField::writeLibrary(..)",
+            dict
+        )   << "Failed writing " << nl
+            << copyFiles << nl
+            << filesContents
+            << exit(FatalIOError);
     }
 }
 
@@ -221,7 +248,7 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
     {
         if (Pstream::master())
         {
-            Foam::string wmakeCmd("wmake libso " + dir);
+            const Foam::string wmakeCmd("wmake libso " + dir);
             Info<< "Invoking " << wmakeCmd << endl;
             if (Foam::system(wmakeCmd))
             {
@@ -229,7 +256,8 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
                 (
                     "codedFixedValueFvPatchScalarField::updateLibrary()",
                     dict_
-                )   << "Failed " << wmakeCmd << exit(FatalIOError);
+                )   << "Failed " << wmakeCmd
+                    << exit(FatalIOError);
             }
         }
 
@@ -242,7 +270,8 @@ void Foam::codedFixedValueFvPatchScalarField::updateLibrary()
             (
                 "codedFixedValueFvPatchScalarField::updateLibrary()",
                 dict_
-            )   << "Failed loading library " << libPath << exit(FatalIOError);
+            )   << "Failed loading library " << libPath
+                << exit(FatalIOError);
         }
     }
 }
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H
index 9b3ed6debf9065825b157998282c60236390197b..25b259b84c37aaf8b11f2930cf9b141a5c31b328 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H
+++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchScalarField.H
@@ -32,7 +32,7 @@ Description
     See also codeStream.
 
     Example:
-
+    \verbatim
         movingWall
         {
             type            codedFixedValue<scalar>;
@@ -53,13 +53,14 @@ Description
             //#{
             //    -I$(LIB_SRC)/finiteVolume/lnInclude
             //#};
-
         }
+    \endverbatim
 
     A special form is if the 'code' section is not supplied. In this case
     the code gets read from a (runTimeModifiable!) dictionary system/codeDict
     which would have an entry
 
+    \verbatim
     rampedFixedValue
     {
         code
@@ -67,6 +68,10 @@ Description
             operator==(min(10, 0.1*this->db().time().value()));
         #};
     }
+    \endverbatim
+
+SeeAlso
+    Foam::codeStreamTools for constant paths used
 
 SourceFiles
     codedFixedValueFvPatchScalarField.C
@@ -86,7 +91,7 @@ namespace Foam
 class codeProperties;
 
 /*---------------------------------------------------------------------------*\
-          Class codedFixedValueFvPatchScalarField Declaration
+              Class codedFixedValueFvPatchScalarField Declaration
 \*---------------------------------------------------------------------------*/
 
 class codedFixedValueFvPatchScalarField
@@ -108,8 +113,8 @@ class codedFixedValueFvPatchScalarField
 
         void writeLibrary
         (
-            const fileName dir,
-            const fileName libPath,
+            const fileName& dir,
+            const fileName& libPath,
             const dictionary& dict
         );
 
@@ -117,6 +122,15 @@ class codedFixedValueFvPatchScalarField
 
 public:
 
+    // Static data members
+
+        //- Name of the C code template to be used
+        const static word codeTemplateC;
+
+        //- Name of the H code template to be used
+        const static word codeTemplateH;
+
+
     //- Runtime type information
     TypeName("codedFixedValue<scalar>");