diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6d6293289cfbb853d5952eb52d1ba16ccbd30c17..4e9f240808afa97fa91771f8a86bf2824d97c5fc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 * Removed duplicated entries from generated `.dep` files
 
 ### Other changes
+* Removed `<module>_TEMPLATES` in favour of `<module>_DB`
 * Removed unnecessary code from `make init`.
 * removed `e3.cfg`, `ess-env.conf` and `DEFINES_REQUIRE` files and associated codes in `RULES_REQUIRE`, `setE3Env.bash` and `.gitignore`.
 * removed legacy code from setE3Env.bash
diff --git a/require-ess/src/require.c b/require-ess/src/require.c
index bda302bc48d8a0a32679ccd2254c209bda9877b9..21cb4ad43b70640d43e2c08fd2856d2e3ee4ee3a 100644
--- a/require-ess/src/require.c
+++ b/require-ess/src/require.c
@@ -1,12 +1,12 @@
 /*
-* ld - load code dynamically
-*
-* $Author: zimoch $
-* $ID$
-* $Date: 2015/06/29 09:47:30 $
-*
-* DISCLAIMER: Use at your own risc and so on. No warranty, no refund.
-*/
+ * ld - load code dynamically
+ *
+ * $Author: zimoch $
+ * $ID$
+ * $Date: 2015/06/29 09:47:30 $
+ *
+ * DISCLAIMER: Use at your own risc and so on. No warranty, no refund.
+ */
 
 #ifdef __unix
 /* for vasprintf and dl_iterate_phdr */
@@ -351,9 +351,29 @@ void pathAdd(const char *varname, const char *dirname)
     }
 }
 
+char *realpathSeparator(const char *location)
+{
+    size_t ll;
+    char *buffer = malloc(PATH_MAX + strlen(OSI_PATH_SEPARATOR));
+    buffer = realpath(location, buffer);
+    if (!buffer)
+    {
+        if (requireDebug)
+            printf("require: realpath(%s) failed\n", location);
+        return NULL;
+    }
+    ll = strlen(buffer);
+    /* linux realpath removes trailing slash */
+    if (buffer[ll - strlen(OSI_PATH_SEPARATOR)] != OSI_PATH_SEPARATOR[0])
+    {
+        strcpy(buffer + ll + 1 - strlen(OSI_PATH_SEPARATOR), OSI_PATH_SEPARATOR);
+    }
+    return buffer;
+}
+
 static int setupDbPath(const char *module, const char *dbdir)
 {
-    char *absdir = realpath(dbdir, NULL); /* so we can change directory later safely */
+    char *absdir = realpathSeparator(dbdir); /* so we can change directory later safely */
     if (absdir == NULL)
     {
         if (requireDebug)
@@ -365,14 +385,12 @@ static int setupDbPath(const char *module, const char *dbdir)
         printf("require: found template directory %s\n", absdir);
 
     /* set up db search path environment variables
-      <module>_TEMPLATES      template path of <module>
       <module>_DB             template path of <module>
       TEMPLATES               template path of the current module (overwritten)
       EPICS_DB_INCLUDE_PATH   template path of all loaded modules (last in front after ".")
     */
 
     putenvprintf("%s_DB=%s", module, absdir);
-    putenvprintf("%s_TEMPLATES=%s", module, absdir);
     putenvprintf("TEMPLATES=%s", absdir);
     pathAdd("EPICS_DB_INCLUDE_PATH", absdir);
     free(absdir);
@@ -502,7 +520,6 @@ void registerModule(const char *module, const char *version, const char *locatio
     size_t ll = 1;
     char *abslocation = NULL;
     char *argstring = NULL;
-    int addSlash = 0;
     const char *mylocation;
     static int firstTime = 1;
 
@@ -522,17 +539,10 @@ void registerModule(const char *module, const char *version, const char *locatio
 
     if (location)
     {
-        abslocation = realpath(location, NULL);
-        if (!abslocation)
-            abslocation = (char *)location;
+        abslocation = realpathSeparator(location);
         ll = strlen(abslocation) + 1;
-        /* linux realpath removes trailing slash */
-        if (abslocation[ll - 1 - strlen(OSI_PATH_SEPARATOR)] != OSI_PATH_SEPARATOR[0])
-        {
-            addSlash = strlen(OSI_PATH_SEPARATOR);
-        }
     }
-    m = (moduleitem *)malloc(sizeof(moduleitem) + lm + lv + ll + addSlash);
+    m = (moduleitem *)malloc(sizeof(moduleitem) + lm + lv + ll);
     if (m == NULL)
     {
         fprintf(stderr, "require: out of memory\n");
@@ -545,10 +555,7 @@ void registerModule(const char *module, const char *version, const char *locatio
     strcpy(m->content + lm, version);
     strcpy(m->content + lm + lv, abslocation ? abslocation : "");
 
-    if (addSlash)
-        strcpy(m->content + lm + lv + ll - 1, OSI_PATH_SEPARATOR);
-    if (abslocation != location)
-        free(abslocation);
+    free(abslocation);
     for (pm = &loadedModules; *pm != NULL; pm = &(*pm)->next)
         ;
     *pm = m;
@@ -842,7 +849,7 @@ static int compareNumericVersion(semver_t *sv_found, semver_t *sv_request, int a
     {
         return match;
     }
-    
+
     if (sv_request->build == -1)
     {
         if (already_matched)
@@ -855,7 +862,7 @@ static int compareNumericVersion(semver_t *sv_found, semver_t *sv_request, int a
             debug("require: compareVersions: No build number requested. Returning MATCH\n");
             return MATCH;
         }
-    } 
+    }
     return compareDigit(sv_found->build, sv_request->build, "build");
 }
 
@@ -898,19 +905,19 @@ static int compareVersions(const char *found, const char *request, int already_m
         {
             debug("require: compareVersions: Test versions requested and found, no match\n");
             match = MISMATCH;
-        } 
+        }
         else
         {
             debug("require: compareVersions: found numeric version, higher than test\n");
             match = HIGHER;
         }
-    } 
+    }
     else if (strlen(sv_found->test_str) > 0)
     {
         debug("require: compareVersions: Numeric version requested, test version found\n");
         match = MISMATCH;
     }
-    else 
+    else
     {
         match = compareNumericVersion(sv_found, sv_request, already_matched);
     }