include config.mk
 
-SRC = surf.c
+SRC = surf.c common.c
 OBJ = $(SRC:.c=.o)
-LIBSRC = libsurf-webext.c
+LIBSRC = libsurf-webext.c common.c
 LIBOBJ = $(LIBSRC:.c=.lo)
 
 all: options libsurf-webext.la surf
 libsurf-webext.la: $(LIBOBJ)
        @echo libtool link $@
        @$(LIBTOOL) --mode link --tag CC $(CC) $(LIBLDFLAGS) -o $@ \
-           $(LIBOBJ) -rpath $(DESTDIR)$(LIBPREFIX)
+           $(LIBOBJ) $(LIB) -rpath $(DESTDIR)$(LIBPREFIX)
 
 surf: $(OBJ)
        @echo CC -o $@
 
--- /dev/null
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void
+die(const char *errstr, ...)
+{
+       va_list ap;
+
+       va_start(ap, errstr);
+       vfprintf(stderr, errstr, ap);
+       va_end(ap);
+       exit(1);
+}
+
 
--- /dev/null
+#define MSGBUFSZ 32
+
+void die(char *, ...);
 
 #include <webkitdom/webkitdom.h>
 #include <webkitdom/WebKitDOMDOMWindowUnstable.h>
 
-#define LENGTH(x)   (sizeof(x) / sizeof(x[0]))
+#include "common.h"
 
-#define MSGBUFSZ 32
+#define LENGTH(x)   (sizeof(x) / sizeof(x[0]))
 
 typedef struct Page {
        guint64 id;
 
 #include <glib.h>
 
 #include "arg.h"
+#include "common.h"
 
 #define LENGTH(x)               (sizeof(x) / sizeof(x[0]))
 #define CLEANMASK(mask)         (mask & (MODKEY|GDK_SHIFT_MASK))
-#define MSGBUFSZ 32
 
 enum { AtomFind, AtomGo, AtomUri, AtomLast };
 
 
 /* Surf */
 static void usage(void);
-static void die(const char *errstr, ...);
 static void setup(void);
 static void sigchld(int unused);
 static void sighup(int unused);
            "[-r scriptfile] [-u useragent] [-z zoomlevel] [uri]\n");
 }
 
-void
-die(const char *errstr, ...)
-{
-       va_list ap;
-
-       va_start(ap, errstr);
-       vfprintf(stderr, errstr, ap);
-       va_end(ap);
-       exit(1);
-}
-
 void
 setup(void)
 {