diff --git a/examples/thttpd/content/Makefile b/examples/thttpd/content/Makefile
index 9df3ec93a1afc152d4f2bd46e3e6f3ce1ba6fcea..1e9937aa655512fe60ad9c9b6e9b59525ac6e7ea 100644
--- a/examples/thttpd/content/Makefile
+++ b/examples/thttpd/content/Makefile
@@ -70,10 +70,10 @@ install: $(foreach DIR, $(SUBDIRS), $(DIR)_install)
 # Create the romfs directory
 
 $(ROMFS_DIR):
-	@mkdir $(ROMFS_DIR)
+	@mkdir -p $(ROMFS_DIR)
 
 $(ROMFSCGI_DIR): $(ROMFS_DIR)
-	@mkdir $(ROMFSCGI_DIR)
+	@mkdir -p $(ROMFSCGI_DIR)
 
 # Populate the romfs directory
 
diff --git a/examples/thttpd/main.c b/examples/thttpd/main.c
index 2e77b39d7b84f7f9e51bbc4c8a61d7daf2c3f52c..23c27256549bfe23d2e9796586354bd5b82c6c3b 100644
--- a/examples/thttpd/main.c
+++ b/examples/thttpd/main.c
@@ -228,7 +228,8 @@ int user_start(int argc, char *argv[])
   g_thttpdsymtab   = exports;
   g_thttpdnsymbols = NEXPORTS;
 
-  printf("Starting THTTPD\n");
+  message("Starting THTTPD\n");
   thttpd_main(1, &thttpd_argv);
+  message("THTTPD terminated\n");
   return 0;
 }
diff --git a/net/net_close.c b/net/net_close.c
index 4a486d9721d03bc445cc33f57ab35d584b2f7e20..7432d2482c26b97797402beef2b3b8a1c0e9c47c 100644
--- a/net/net_close.c
+++ b/net/net_close.c
@@ -245,8 +245,9 @@ int net_close(int sockfd)
                 {
                   /* Yes... free the connection structure */
 
-                 uip_unlisten(conn);          /* No longer accepting connections */
+                  uip_unlisten(conn);          /* No longer accepting connections */
                   netclose_disconnect(psock);  /* Break any current connections */
+                  conn->crefs = 0;             /* No more references on the connection */
                   uip_tcpfree(conn);           /* Free uIP resources */
                 }
               else
diff --git a/netutils/thttpd/libhttpd.c b/netutils/thttpd/libhttpd.c
index f35b6a76772d5b69d512b0def12aa8d0a349699f..32c147cac81d7d8eb33ae4e6d97f4dddbd68d09e 100644
--- a/netutils/thttpd/libhttpd.c
+++ b/netutils/thttpd/libhttpd.c
@@ -272,16 +272,19 @@ char *httpd_err503form    = "The requested URL '%s' is temporarily overloaded.
 
 static void free_httpd_server(httpd_server * hs)
 {
-  if (hs->binding_hostname)
+  if (hs)
     {
-      free((void *)hs->binding_hostname);
-    }
+      if (hs->hostname)
+        {
+          free(hs->hostname);
+        }
 
-  if (hs->cwd)
-    {
-      free((void *)hs->cwd);
+      if (hs->cwd)
+        {
+          free(hs->cwd);
+        }
+      free(hs);
     }
-  free((void *)hs);
 }
 
 static int initialize_listen_socket(httpd_sockaddr *saP)
@@ -300,10 +303,11 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
 
   /* Create socket. */
 
+  nvdbg("Create listen socket\n");
   listen_fd = socket(saP->sin_family, SOCK_STREAM, 0);
   if (listen_fd < 0)
     {
-      ndbg("socket %s: %d\n", httpd_ntoa(saP), errno);
+      ndbg("socket failed: %d\n", errno);
       return -1;
     }
 
@@ -312,14 +316,14 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
   on = 1;
   if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
     {
-      ndbg("setsockopt SO_REUSEADDR: %d\n", errno);
+      ndbg("setsockopt(SO_REUSEADDR) failed: %d\n", errno);
     }
 
   /* Bind to it. */
 
   if (bind(listen_fd, (struct sockaddr*)&saP, sockaddr_len(saP)) < 0)
     {
-      ndbg("bind %s: %d\n", httpd_ntoa(saP), errno);
+      ndbg("bind to %s failed: %d\n", httpd_ntoa(saP), errno);
       (void)close(listen_fd);
       return -1;
     }
@@ -329,14 +333,14 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
   flags = fcntl(listen_fd, F_GETFL, 0);
   if (flags == -1)
     {
-      ndbg("fcntl F_GETFL: %d\n", errno);
+      ndbg("fcntl(F_GETFL) failed: %d\n", errno);
       (void)close(listen_fd);
       return -1;
     }
 
   if (fcntl(listen_fd, F_SETFL, flags | O_NDELAY) < 0)
     {
-      ndbg("fcntl O_NDELAY: %d\n", errno);
+      ndbg("fcntl(O_NDELAY) failed: %d\n", errno);
       (void)close(listen_fd);
       return -1;
     }
@@ -345,7 +349,7 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
 
   if (listen(listen_fd, CONFIG_THTTPD_LISTEN_BACKLOG) < 0)
     {
-      ndbg("listen: %d\n", errno);
+      ndbg("listen failed: %d\n", errno);
       (void)close(listen_fd);
       return -1;
     }
@@ -2053,7 +2057,7 @@ static void create_environment(httpd_conn *hc)
   else
 #endif
     {
-      cp = hc->hs->server_hostname;
+      cp = hc->hs->hostname;
     }
 
   if (cp)
@@ -3163,7 +3167,7 @@ static int check_referer(httpd_conn *hc)
       else
 #endif
         {
-          cp = hc->hs->server_hostname;
+          cp = hc->hs->hostname;
         }
 
       if (cp == NULL)
@@ -3247,7 +3251,7 @@ static int really_check_referer(httpd_conn *hc)
 #ifndef CONFIG_THTTPD_VHOST
   /* Not vhosting, use the server name. */
 
-  lp = hs->server_hostname;
+  lp = hs->hostname;
   if (!lp)
     {
       /* Couldn't figure out local hostname - give up. */
@@ -3332,13 +3336,15 @@ FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa, FAR const char *cwd)
 {
   FAR httpd_server *hs;
 
+  nvdbg("cwd: %s\n", cwd);
+
   /* Save the PID of the main thread */
 
   main_thread = getpid();
 
   /* Allocate the server structure */
 
-  hs = NEW(httpd_server, 1);
+  hs = (FAR httpd_server *)zalloc(sizeof(httpd_server));
   if (!hs)
     {
       ndbg("out of memory allocating an httpd_server\n");
@@ -3346,12 +3352,13 @@ FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa, FAR const char *cwd)
     }
 
 #ifdef CONFIG_THTTPD_HOSTNAME
-  hs->server_hostname = strdup(CONFIG_THTTPD_HOSTNAME);
+  hs->hostname = strdup(CONFIG_THTTPD_HOSTNAME);
 #else
-  hs->server_hostname = strdup(httpd_ntoa(sa));
+  hs->hostname = strdup(httpd_ntoa(sa));
 #endif
+  nvdbg("hostname: %s\n", hs->hostname);
 
-  if (!hs->server_hostname)
+  if (!hs->hostname)
     {
       ndbg("out of memory copying hostname\n");
       return NULL;
@@ -3370,10 +3377,12 @@ FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa, FAR const char *cwd)
   hs->listen_fd = initialize_listen_socket(sa);
   if (hs->listen_fd == -1)
     {
+      ndbg("Failed to create listen socket\n");
       free_httpd_server(hs);
-      return (httpd_server *) 0;
+      return NULL;
     }
 
+  nvdbg("Calling init_mime()\n");
   init_mime();
 
   /* Done initializing. */
diff --git a/netutils/thttpd/libhttpd.h b/netutils/thttpd/libhttpd.h
index aed4b8194818930833e018110d744ba7035b69ee..fc0aa490be89bd4b84dac0866ec3047a54067393 100644
--- a/netutils/thttpd/libhttpd.h
+++ b/netutils/thttpd/libhttpd.h
@@ -114,8 +114,7 @@ typedef struct sockaddr_in httpd_sockaddr;
 
 typedef struct
 {
-  char *binding_hostname;
-  char *server_hostname;
+  char *hostname;
   int   cgi_count;
   char *cwd;
   int   listen_fd;
diff --git a/netutils/thttpd/thttpd.c b/netutils/thttpd/thttpd.c
index a2aa1c330af2d5f47d57e33c899248f09b7b5d1b..aac9e4425d972b8d8ca508dc64192de7143b4b34 100644
--- a/netutils/thttpd/thttpd.c
+++ b/netutils/thttpd/thttpd.c
@@ -175,7 +175,7 @@ static void shut_down(void)
         }
     }
 
-  if (hs != (httpd_server *) 0)
+  if (hs)
     {
       httpd_server *ths = hs;
       hs = (httpd_server *) 0;
@@ -747,6 +747,8 @@ int thttpd_main(int argc, char **argv)
   int ret;
 #endif
 
+  nvdbg("THTTPD started\n");
+
   /* Setup host address */
 
 #ifdef  CONFIG_NET_IPv6
@@ -803,9 +805,11 @@ int thttpd_main(int argc, char **argv)
 
   /* Initialize the HTTP layer */
 
+  nvdbg("Calling httpd_initialize()\n");
   hs = httpd_initialize(&sa, cwd);
   if (!hs)
     {
+      ndbg("httpd_initialize() failed\n");
       exit(1);
     }
 
@@ -870,6 +874,7 @@ int thttpd_main(int argc, char **argv)
 
   /* Main loop */
 
+  nvdbg("Entering the main loop\n");
   (void)gettimeofday(&tv, (struct timezone *)0);
   while ((!terminate) || num_connects > 0)
     {