diff --git a/src/curlutil.c b/src/curlutil.c
index bca2db7aa3025e636a5472eda6923f691e82bb5b..a524b65b4e92977a89efa7e6c7a37e24df14c0fb 100644
--- a/src/curlutil.c
+++ b/src/curlutil.c
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -19,11 +19,12 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
-
 #include "setup.h"
 
 #include "curlutil.h"
 
+#include "memdebug.h" /* keep this as LAST include */
+
 #if defined(WIN32) && !defined(MSDOS)
 
 struct timeval cutil_tvnow(void)
diff --git a/src/curlutil.h b/src/curlutil.h
index a993a775e22df48950235e247c805eb9524b8056..e0d9cb16711f9f3face5efaf680639cc3898815a 100644
--- a/src/curlutil.h
+++ b/src/curlutil.h
@@ -1,5 +1,5 @@
-#ifndef __CURL_SRC_UTIL_H
-#define __CURL_SRC_UTIL_H
+#ifndef HEADER_CURL_SRC_UTIL_H
+#define HEADER_CURL_SRC_UTIL_H
 /***************************************************************************
  *                                  _   _ ____  _
  *  Project                     ___| | | |  _ \| |
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -21,7 +21,6 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
-
 #include "setup.h"
 
 
@@ -45,5 +44,5 @@ double cutil_tvdiff_secs(struct timeval t1, struct timeval t2);
 long cutil_tvlong(struct timeval t1);
 
 
-#endif  /* __CURL_SRC_UTIL_H */
+#endif  /* HEADER_CURL_SRC_UTIL_H */
 
diff --git a/src/getpass.c b/src/getpass.c
index 438fc8d3186025e6c93615c1ee0f383e9922eaa1..a154d107c7ee22ce8373930f723aa507dc926539 100644
--- a/src/getpass.c
+++ b/src/getpass.c
@@ -19,10 +19,6 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
-
-/* This file is a reimplementation of the previous one, due to license
-   problems. */
-
 #include "setup.h"
 
 #ifndef HAVE_GETPASS_R
@@ -32,8 +28,6 @@
 #include <unistd.h>
 #endif
 
-#include "getpass.h"
-
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
@@ -45,17 +39,30 @@
 #endif
 #endif
 
-/* The last #include file should be: */
-#if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
-#include "memdebug.h"
+#ifdef __VMS
+#  include descrip
+#  include starlet
+#  include iodef
+#endif
+
+#ifdef WIN32
+#  include <conio.h>
+#endif
+
+#ifdef NETWARE
+#  ifdef __NOVELL_LIBC__
+#    include <screen.h>
+#  else
+#    include <nwconio.h>
+#  endif
 #endif
 
+#include "getpass.h"
+
+#include "memdebug.h" /* keep this as LAST include */
+
 #ifdef __VMS
 /* VMS implementation */
-#include descrip
-#include starlet
-#include iodef
-/* #include iosbdef */
 char *getpass_r(const char *prompt, char *buffer, size_t buflen)
 {
   long sts;
@@ -91,12 +98,6 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
 #define DONE
 #endif /* __VMS */
 
-
-#ifdef WIN32
-/* Windows implementation */
-#include <conio.h>
-#endif
-
 #ifdef __SYMBIAN32__
 #define getch() getchar()
 #endif
@@ -136,13 +137,11 @@ char *getpass_r(const char *prompt, char *buffer, size_t buflen)
 #ifdef NETWARE
 /* NetWare implementation */
 #ifdef __NOVELL_LIBC__
-#include <screen.h>
 char *getpass_r(const char *prompt, char *buffer, size_t buflen)
 {
   return getpassword(prompt, buffer, buflen);
 }
 #else
-#include <nwconio.h>
 char *getpass_r(const char *prompt, char *buffer, size_t buflen)
 {
   size_t i = 0;
diff --git a/src/getpass.h b/src/getpass.h
index 3b29d47a1ffd26a299c1bfff4fe10477540db9d6..7d714fcf33b80d0d85a1d917483f76fd71940bbb 100644
--- a/src/getpass.h
+++ b/src/getpass.h
@@ -1,5 +1,5 @@
-#ifndef __GETPASS_H
-#define __GETPASS_H
+#ifndef HEADER_CURL_GETPASS_H
+#define HEADER_CURL_GETPASS_H
 /***************************************************************************
  *                                  _   _ ____  _
  *  Project                     ___| | | |  _ \| |
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -21,6 +21,8 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
+#include "setup.h"
+
 #ifndef HAVE_GETPASS_R
 /* If there's a system-provided function named like this, we trust it is
    also found in one of the standard headers. */
@@ -31,4 +33,4 @@
 char* getpass_r(const char *prompt, char* buffer, size_t buflen );
 #endif
 
-#endif
+#endif /* HEADER_CURL_GETPASS_H */
diff --git a/src/homedir.c b/src/homedir.c
index d354ef906c4e6d6c4cb131a4204849b531c8e728..80ffe0752c88dd227e11e8f219fce0c6e468e00d 100644
--- a/src/homedir.c
+++ b/src/homedir.c
@@ -19,7 +19,6 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
-
 #include "setup.h"
 
 #ifdef HAVE_PWD_H
@@ -34,9 +33,7 @@
 
 #include "homedir.h"
 
-#if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
-#include "memdebug.h"
-#endif
+#include "memdebug.h" /* keep this as LAST include */
 
 static
 char *GetEnv(const char *variable, char do_expand)
diff --git a/src/homedir.h b/src/homedir.h
index c88d517239bb39873ac510ea673ef2cb80bdb911..252fd0ecc751a4b20833549040290ac7fe5b1192 100644
--- a/src/homedir.h
+++ b/src/homedir.h
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -21,6 +21,7 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
+#include "setup.h"
 
 char *homedir(void);
 
diff --git a/src/hugehelp.h b/src/hugehelp.h
index b84be17f54f6d31efbdd15c46e9ce78fb04606b6..842836dda06c1f2afcdd272ff19ad358eef75ff6 100644
--- a/src/hugehelp.h
+++ b/src/hugehelp.h
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -21,6 +21,8 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
+#include "setup.h"
+
 void hugehelp(void);
 
 #endif /* HEADER_CURL_HUGEHELP_H */
diff --git a/src/main.c b/src/main.c
index 3c3d99f98b8512422bec2237eba904905881ca44..ebcc93cd3d1a8efa6ef3dd18418f70d222e1d667 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,7 +19,6 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
-
 #include "setup.h"
 
 #include <curl/curl.h>
@@ -138,16 +137,10 @@
    versions instead */
 #include "curlx.h"
 
-/* The last #include file should be: */
-#ifdef CURLDEBUG
-#ifndef CURLTOOLDEBUG
-#define MEMDEBUG_NODEFINES
-#endif
 /* This is low-level hard-hacking memory leak tracking and similar. Using
    the library level code from this client-side is ugly, but we do this
    anyway for convenience. */
-#include "memdebug.h"
-#endif
+#include "memdebug.h" /* keep this as LAST include */
 
 #ifdef __VMS
 static int vms_show = 0;
diff --git a/src/mkhelp.pl b/src/mkhelp.pl
index d09d6c50862ec1c49a8f8aad2ccb1319298698cd..ff4604155bc1fb1eb6823d10cae76a26dfa77e49 100644
--- a/src/mkhelp.pl
+++ b/src/mkhelp.pl
@@ -140,9 +140,7 @@ HEAD
 if($c) {
     print <<HEAD
 #include <zlib.h>
-#if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
-#include "memdebug.h"
-#endif
+#include "memdebug.h" /* keep this as LAST include */
 static const unsigned char hugehelpgz[] = {
   /* This mumbo-jumbo is the huge help text compressed with gzip.
      Thanks to this operation, the size of this data shrunk from $gzip
diff --git a/src/os-specific.c b/src/os-specific.c
index ac07c4cecae52d5ad43be4a62efd4d8024996ec2..f9587176164d88cfe2db473aebe45017f4d3d426 100644
--- a/src/os-specific.c
+++ b/src/os-specific.c
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -21,20 +21,22 @@
  ***************************************************************************/
 #include "setup.h"
 
+#ifdef __VMS
+
+#if defined(__DECC) && !defined(__VAX) && \
+    defined(__CRTL_VER) && (__CRTL_VER >= 70301000)
+#include <unixlib.h>
+#endif
+
 #include <curl/curl.h>
 
 #define ENABLE_CURLX_PRINTF
 #include "curlx.h"
 
+#include "curlmsg_vms.h"
 #include "os-specific.h"
 
-#if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
-#  include "memdebug.h"
-#endif
-
-#ifdef __VMS
-
-#include "curlmsg_vms.h"
+#include "memdebug.h" /* keep this as LAST include */
 
 void decc$__posix_exit(int __status);
 void decc$exit(int __status);
@@ -121,8 +123,6 @@ void vms_special_exit(int code, int vms_show)
  * requiring the user to define the corresponding logical names.
  */
 
-#include <unixlib.h>
-
 /* Structure to hold a DECC$* feature name and its desired value. */
 typedef struct {
   char *name;
diff --git a/src/os-specific.h b/src/os-specific.h
index 93cac743cc0edb7fdce1b2c91450c141e05d0fbb..4e6ac624737db02a0607b77221e4932da88d74da 100644
--- a/src/os-specific.h
+++ b/src/os-specific.h
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -21,6 +21,7 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
+#include "setup.h"
 
 #ifdef __VMS
 
diff --git a/src/urlglob.c b/src/urlglob.c
index 9b2de424aa6869b0b06c2624259085cdd95ab4aa..80b59b46ec5e7565fb6ee50268b4e960a69f8d8a 100644
--- a/src/urlglob.c
+++ b/src/urlglob.c
@@ -19,8 +19,6 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
-
-/* client-local setup.h */
 #include "setup.h"
 
 #include <curl/curl.h>
@@ -31,9 +29,7 @@
 #include "urlglob.h"
 #include "os-specific.h"
 
-#if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
-#include "memdebug.h"
-#endif
+#include "memdebug.h" /* keep this as LAST include */
 
 typedef enum {
   GLOB_OK,
diff --git a/src/urlglob.h b/src/urlglob.h
index a5b789e6b8e7988d7b6b5cd0b5bf9170e041608b..44681ea908bdee1638703dea32d03f424f8cb4a8 100644
--- a/src/urlglob.h
+++ b/src/urlglob.h
@@ -1,5 +1,5 @@
-#ifndef __URLGLOB_H
-#define __URLGLOB_H
+#ifndef HEADER_CURL_URLGLOB_H
+#define HEADER_CURL_URLGLOB_H
 /***************************************************************************
  *                                  _   _ ____  _
  *  Project                     ___| | | |  _ \| |
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -21,6 +21,8 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
+#include "setup.h"
+
 typedef enum {
   UPTSet=1,
   UPTCharRange,
@@ -64,4 +66,4 @@ char* glob_next_url(URLGlob*);
 char* glob_match_url(char*, URLGlob *);
 void glob_cleanup(URLGlob* glob);
 
-#endif
+#endif /* HEADER_CURL_URLGLOB_H */
diff --git a/src/version.h b/src/version.h
index ce83b8579b0d3310b708f7c45feff36811790d2e..a4116b77debbc418698771459e34faf9db3262df 100644
--- a/src/version.h
+++ b/src/version.h
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -21,6 +21,7 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
+#include "setup.h"
 
 #include <curl/curlver.h>
 
diff --git a/src/writeenv.c b/src/writeenv.c
index e3edbec75c05acd8cbb8a607b08c1a0b7857af40..b509449e23a7f1c285740981cd9fafee1b1fe81d 100644
--- a/src/writeenv.c
+++ b/src/writeenv.c
@@ -19,24 +19,22 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
-
 #include "setup.h"
 
 #ifdef USE_ENVIRONMENT
 
-#include <curl/curl.h>
-#include "writeenv.h"
-
 #ifdef __riscos__
 #include <kernel.h>
 #endif
 
+#include <curl/curl.h>
+
 #define _MPRINTF_REPLACE /* use our functions only */
 #include <curl/mprintf.h>
 
-#if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
-#include "memdebug.h"
-#endif
+#include "writeenv.h"
+
+#include "memdebug.h" /* keep this as LAST include */
 
 static const struct
 {
diff --git a/src/writeenv.h b/src/writeenv.h
index 8d92f6c895c4f96cdfb05de7c3a127e705706fce..0816c34f9c82563674164fe48e34509b53947a3b 100644
--- a/src/writeenv.h
+++ b/src/writeenv.h
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -21,6 +21,7 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
+#include "setup.h"
 
 void ourWriteEnv(CURL *curl);
 
diff --git a/src/writeout.c b/src/writeout.c
index 3e854ec829f83644f67caee20866185a5e0eb432..7e41050676c4bf72685a358c0abd725b819d32b0 100644
--- a/src/writeout.c
+++ b/src/writeout.c
@@ -19,7 +19,6 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
-
 #include "setup.h"
 
 #ifdef HAVE_SYS_TYPES_H
@@ -36,6 +35,8 @@
 
 #include "writeout.h"
 
+#include "memdebug.h" /* keep this as LAST include */
+
 typedef enum {
   VAR_NONE,       /* must be the first */
   VAR_TOTAL_TIME,
diff --git a/src/writeout.h b/src/writeout.h
index 1b221026e420bb2b19db5e1d016587935de3029d..92d8ea5a9943b99b1cd84ba1d3fc67e000494e78 100644
--- a/src/writeout.h
+++ b/src/writeout.h
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -21,6 +21,7 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
+#include "setup.h"
 
 void ourWriteOut(CURL *curl, const char *out);
 
diff --git a/src/xattr.c b/src/xattr.c
index 1600d88c6e58ed40cb8f615f00725d380f8bed83..146acf94c5868d340ef5fd94501ed80529703420 100644
--- a/src/xattr.c
+++ b/src/xattr.c
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 2010, 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -19,15 +19,19 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
-
-/* client-local setup.h */
 #include "setup.h"
-#include <curl/curl.h>
-#include "xattr.h"
 
 #ifdef HAVE_FSETXATTR
 #include <sys/types.h>
 #include <sys/xattr.h> /* include header from libc, not from libattr */
+#endif
+
+#include <curl/curl.h>
+#include "xattr.h"
+
+#include "memdebug.h" /* keep this as LAST include */
+
+#ifdef HAVE_FSETXATTR
 
 /* mapping table of curl metadata to extended attribute names */
 static const struct xattr_mapping {
diff --git a/src/xattr.h b/src/xattr.h
index fea98f188f1d2ac0849299339d1babf7708da565..ef528eafae49198dce88e2c51bbc58302ca1b3e4 100644
--- a/src/xattr.h
+++ b/src/xattr.h
@@ -1,5 +1,5 @@
-#ifndef __XATTR_H
-#define __XATTR_H
+#ifndef HEADER_CURL_XATTR_H
+#define HEADER_CURL_XATTR_H
 /***************************************************************************
  *                                  _   _ ____  _
  *  Project                     ___| | | |  _ \| |
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -21,6 +21,8 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
+#include "setup.h"
+
 int fwrite_xattr(CURL *curl, int fd);
 
-#endif
+#endif /* HEADER_CURL_XATTR_H */