diff --git a/src/aec.c b/src/aec.c
index b3c6a36b6eb6591b309643bcb748b104412be230..23a8a66dde358f31b383b5c029f3b37ce42f2706 100644
--- a/src/aec.c
+++ b/src/aec.c
@@ -47,12 +47,12 @@
  *
  */
 
+#include "config.h"
+#include "libaec.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "libaec.h"
-
 #define CHUNK 10485760
 
 int get_param(unsigned int *param, int *iarg, char *argv[])
diff --git a/src/decode.c b/src/decode.c
index 160d4c35d0cd81cc6f564c11505754b09e4e0734..3c75ddb3b1c69110ed8aa84baf7eab80544fb565 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -48,15 +48,15 @@
  *
  */
 
+#include "config.h"
+#include "decode.h"
+#include "libaec.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "decode.h"
-#include "libaec.h"
-
 #if HAVE_BSR64
-#  include <intrin.h>
+#include <intrin.h>
 #endif
 
 #define ROS 5
diff --git a/src/decode.h b/src/decode.h
index d747080770af3e5e75f7833d1f579dee3ff9872d..bda62173f1a58e89000171a893071c1163156d41 100644
--- a/src/decode.h
+++ b/src/decode.h
@@ -51,9 +51,9 @@
 #ifndef DECODE_H
 #define DECODE_H 1
 
-#include <config.h>
-
+#include "config.h"
 #include <stdint.h>
+#include <stddef.h>
 
 #define M_CONTINUE 1
 #define M_EXIT 0
diff --git a/src/encode.c b/src/encode.c
index 301284e87d9f794f013add5b8f32721f73682a26..f0c70e6d81c959f7b3494f4b021231c85216d852 100644
--- a/src/encode.c
+++ b/src/encode.c
@@ -48,13 +48,13 @@
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
+#include "config.h"
 #include "encode.h"
 #include "encode_accessors.h"
 #include "libaec.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 static int m_get_block(struct aec_stream *strm);
 
diff --git a/src/encode.h b/src/encode.h
index 8653ab3526e084f4db466e7d8cf87f7af4cfa13a..e02ecaa7e71b04be30446ac459d4a4ff800b4b1f 100644
--- a/src/encode.h
+++ b/src/encode.h
@@ -51,8 +51,7 @@
 #ifndef ENCODE_H
 #define ENCODE_H 1
 
-#include <config.h>
-
+#include "config.h"
 #include <stdint.h>
 
 #define M_CONTINUE 1
diff --git a/src/encode_accessors.c b/src/encode_accessors.c
index 7b0595a2d2bb84ed666021afc67179929fe60951..d664d922d7e3e820a4553d45c9298c57c3bb2cdf 100644
--- a/src/encode_accessors.c
+++ b/src/encode_accessors.c
@@ -47,13 +47,12 @@
  *
  */
 
-#include <config.h>
-
+#include "config.h"
+#include "encode_accessors.h"
+#include "encode.h"
+#include "libaec.h"
 #include <stdint.h>
 #include <string.h>
-#include "libaec.h"
-#include "encode.h"
-#include "encode_accessors.h"
 
 uint32_t aec_get_8(struct aec_stream *strm)
 {
diff --git a/src/encode_accessors.h b/src/encode_accessors.h
index 68180a6a1a1399b61c7bf97dbd7176b99bb0da64..d0b180606c0dd43ac2616e6fa188c127f82f1246 100644
--- a/src/encode_accessors.h
+++ b/src/encode_accessors.h
@@ -51,7 +51,7 @@
 #define ENCODE_ACCESSORS_H 1
 
 #include "config.h"
-
+#include "libaec.h"
 #include <stdint.h>
 
 uint32_t aec_get_8(struct aec_stream *strm);
diff --git a/src/sz_compat.c b/src/sz_compat.c
index f852ed2be9067b5b9334ed6b75debbd3802eae58..588ac19016cc9d7919a495bb43d8153b1ca06bc8 100644
--- a/src/sz_compat.c
+++ b/src/sz_compat.c
@@ -1,10 +1,8 @@
+#include "config.h"
+#include "szlib.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#if HAVE_CONFIG_H
-#  include <config.h>
-#endif
-#include "szlib.h"
 
 #define NOPTS 129
 #define MIN(a, b) (((a) < (b))? (a): (b))
diff --git a/src/szlib.h b/src/szlib.h
index c22362a5d4b20c6f47d62b1957294c5e1651aff1..41fc0196bedb00c4b896f85a2d1d477564827da5 100644
--- a/src/szlib.h
+++ b/src/szlib.h
@@ -1,15 +1,16 @@
 #ifndef SZLIB_H
 #define SZLIB_H 1
 
+#include "config.h"
 #include "libaec.h"
 
-#define SZ_ALLOW_K13_OPTION_MASK         1
-#define SZ_CHIP_OPTION_MASK              2
-#define SZ_EC_OPTION_MASK                4
-#define SZ_LSB_OPTION_MASK               8
-#define SZ_MSB_OPTION_MASK              16
-#define SZ_NN_OPTION_MASK               32
-#define SZ_RAW_OPTION_MASK             128
+#define SZ_ALLOW_K13_OPTION_MASK 1
+#define SZ_CHIP_OPTION_MASK 2
+#define SZ_EC_OPTION_MASK 4
+#define SZ_LSB_OPTION_MASK 8
+#define SZ_MSB_OPTION_MASK 16
+#define SZ_NN_OPTION_MASK 32
+#define SZ_RAW_OPTION_MASK 128
 
 #define SZ_OK AEC_OK
 #define SZ_OUTBUFF_FULL 2