diff --git a/include/ana/globals.h b/include/ana/globals.h
index 50499787c16396b33f10dc1fd1571a2c4a90f3c2..e1968d73141a796d120cf0201624cc580a179ec0 100644
--- a/include/ana/globals.h
+++ b/include/ana/globals.h
@@ -2,10 +2,11 @@
 #define GLOBALS_H
 
 
-#include "logdef.h"
 #include <graphics/newci.h>
 #include <graphics/mylib.h>
 #include <utils/newasm.h>
+#include "logdef.h"
+#include "gate.h"
 
 #ifdef GLOBALS_G
 # define vextern
diff --git a/include/gate.h b/include/gate.h
index 96bd11dbd0e5ccb7c5c28bc2ad12cfa81c58f63e..a4e88f455c1776913a2e79a36435045d5b66e6d1 100644
--- a/include/gate.h
+++ b/include/gate.h
@@ -1,7 +1,6 @@
 #ifndef GATE_H
 #define GATE_H
 
-#include <graphics/mylib.h>
 #include <utils/newasm.h>
 #include "logdef.h"
 
diff --git a/include/graphics/mylib.h b/include/graphics/mylib.h
index f15b2864a523732eb198f12e6503a4ea2950ba76..e076e9038eb1126ec3d6c9f151d941380a6c004f 100644
--- a/include/graphics/mylib.h
+++ b/include/graphics/mylib.h
@@ -2,6 +2,7 @@
 #define MYLIB_H
 
 #include <X11/Xlib.h>
+#include <utils/p2c.h>
 
 typedef uchar m_colorarray[17];
 
@@ -168,6 +169,3 @@ uchar m_inkeyn();
 uchar m_testkey();
 
 #endif /*MYLIB_H*/
-
-
-
diff --git a/include/log_action.h b/include/log_action.h
index 32e99247530f7651ec88df54db2cd003278e0e1b..a1d52ae7e508beb1ae4e2f36c6e4fca866f02f56 100644
--- a/include/log_action.h
+++ b/include/log_action.h
@@ -6,6 +6,7 @@
 #include "wire.h"
 #include "page.h"
 #include "label.h"
+#include <graphics/mylib.h>
 #include <limits.h>
 
 typedef enum
diff --git a/include/logdef.h b/include/logdef.h
index 130a0b76d57d7f8aeac2b94844c00045c4d2db56..24b180ac4747fc16b54619827789db9e306b5ed6 100644
--- a/include/logdef.h
+++ b/include/logdef.h
@@ -2,7 +2,6 @@
 #define LOGDEF_H
 
 #include <utils/p2c.h>
-#include <graphics/mylib.h>
 #include <utils/strlist.h>
 #include <utils/newasm.h>
 
@@ -243,5 +242,4 @@ typedef struct log_colorrec {
 
 #undef vextern
 
-#include <log_action.h>
 #endif /*LOGDEF_H*/
diff --git a/include/loghier.h b/include/loghier.h
index eb44224319b7eba21d29d6d82bd1b60cd2b426e1..1b7d9d73444ffa2c5ce3f8f3c93986444e01ffbd 100644
--- a/include/loghier.h
+++ b/include/loghier.h
@@ -4,6 +4,8 @@
 #include "logdef.h"
 #include <utils/newasm.h>
 #include <graphics/mylib.h>
+#include "gate.h"
+#include "label.h"
 
 void hier_init (log_action_t *act);
 int commandlabel (log_lrec *lp, char *cmd, char *args);
diff --git a/include/logsim.h b/include/logsim.h
index 0c035768672ef061f5e54c0d1c6237f5ca780aee..f1e697a80ecbcd227304058f4e979e7491b6c0d2 100644
--- a/include/logsim.h
+++ b/include/logsim.h
@@ -31,5 +31,3 @@ extern void log_16_noprog (log_16_action *act);
 
 
 #endif /*LOGSIM_H*/
-
-
diff --git a/include/logsima.h b/include/logsima.h
index 18faf6eab73997719c58d7f66d1dcf9276bf2cfd..b6bcf81acca2affa4d7afa4d99d6bffa9dde9229 100644
--- a/include/logsima.h
+++ b/include/logsima.h
@@ -6,6 +6,7 @@
 #include "logdig.h"
 #include <utils/newasm.h>
 #include "tool.h"
+#include "gate.h"
 
 
 #ifdef LOGSIMA_G
@@ -22,7 +23,7 @@ typedef struct nodeinfo {
 typedef struct kindinfo {
   na_long info;
   int hasproc, instance;
-  short numppins, numpvars;
+  short numppins, numpvars; // TODO move in gateinfo
   void (*kindproc) (log_16_action *act);
   log_krec *knext;
 } kindinfo;
diff --git a/include/logstructs.h b/include/logstructs.h
index af24349f240de2c0d90b14a167bbfc05466adda9..d59106fefe18a7e4a6f00989b9cb71bc104538f2 100644
--- a/include/logstructs.h
+++ b/include/logstructs.h
@@ -3,6 +3,9 @@
 
 #include "settings.h"
 #include "logdef.h"
+#include "wire.h"
+#include "gate.h"
+#include "label.h"
 
 /** ??? */
 typedef struct descrec {
diff --git a/include/tool.h b/include/tool.h
index 7c64c49e46673a0907348c9f93bbceaac69c225c..271adf0d733cdc09587428f9b7283d50da2266b7 100644
--- a/include/tool.h
+++ b/include/tool.h
@@ -2,6 +2,8 @@
 #define LOG_TOOL_H
 
 #include "logdef.h"
+#include "gate.h"
+#include "log_action.h"
 
 typedef struct log_tool {
   char name[17];
diff --git a/src/ana/numbers.c b/src/ana/numbers.c
index 4916f6bd9fc4bb94e02a7a8e7e14e65573c377c0..458dc29a7ff32c0df7b36db4772021bc95f45b97 100644
--- a/src/ana/numbers.c
+++ b/src/ana/numbers.c
@@ -27,6 +27,7 @@ the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 #include <utils/p2c.h>
 #include "ana/numbers.h"
+#include "log_action.h"
 
 
 #define TitleX          (-80)
diff --git a/src/ana/thermal.c b/src/ana/thermal.c
index 2962006ceaaa46a40c4e66afc17277e2f041006f..1649b2923bebcb2b841f6cc0e69f46dd2645eed4 100644
--- a/src/ana/thermal.c
+++ b/src/ana/thermal.c
@@ -26,6 +26,7 @@ the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 
 #include <utils/p2c.h>
+#include "log_action.h"
 #include "ana/thermal.h"
 
 #define N_Kelvin       1
diff --git a/src/diggates.c b/src/diggates.c
index 42d3e23f679980094b09459ffcfe1a20a6a213bc..985c5d290b7504fdeae44e18c148354edd8d341a 100644
--- a/src/diggates.c
+++ b/src/diggates.c
@@ -27,6 +27,8 @@
 #include <utils/p2c.h>
 #include <utils/strings.h>
 
+#include "log_action.h"
+#include "gate.h"
 #include "mygates.h"
 
 
diff --git a/src/log.c b/src/log.c
index 290ea1104843524904087d878a0d8650ec80d9e0..f8643c46ee57c8a4fa2d061b842841292edc3dba 100644
--- a/src/log.c
+++ b/src/log.c
@@ -43,6 +43,7 @@
 #include <utils/p2c.h>
 
 #include "logdef.h"
+#include "log_action.h"
 #include <utils/sysglobals.h>
 #include <utils/sysdevs.h>
 
diff --git a/src/loged.c b/src/loged.c
index 6c252eeb67a9bbab7ea74eab172d1a9f55ca281c..ef62bb572c72f69b37a469c39f903ef1bc7f7f9e 100644
--- a/src/loged.c
+++ b/src/loged.c
@@ -52,6 +52,7 @@ the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 
 #include "logdef.h"
+#include "log_action.h"
 #include <graphics/mylib.h>
 #include <graphics/newci.h>
 #include <graphics/newkbd.h>
diff --git a/src/logsim.c b/src/logsim.c
index 0e3231619078f28d9913069dd15ac73e49f83e8e..65111e7b192891a8bda4bdf90189e210637f0ea4 100644
--- a/src/logsim.c
+++ b/src/logsim.c
@@ -37,7 +37,9 @@
 
 #include <utils/p2c.h>
 #include <stdlib.h>
+#include "log_action.h"
 #include "logsim.h"
+#include "logsima.h"
 #include "node.h"
 #include "tool.h"
 #include "logstuff.h"
diff --git a/src/logsimasm.c b/src/logsimasm.c
index 625ec1390c9d30412f97469309318c7ccc5cf9f5..9a8c4d42822df7df43182bc67a1f6d56b1404c71 100644
--- a/src/logsimasm.c
+++ b/src/logsimasm.c
@@ -33,6 +33,7 @@
 
 #include "node.h"
 #include "logstuff.h"
+#include "log_action.h"
 
 #define trace_16  (logsima_action.lact->quiet ? -1 : 0)