diff --git a/unparse.lisp b/unparse.lisp
index f36acb1..d4ef4ae 100644
--- a/unparse.lisp
+++ b/unparse.lisp
@@ -72,12 +72,44 @@
                         :extra-namespaces ,extra-namespaces
                         :process-aliases ,process-aliases))
 
+(defstruct profile-counter calls run real)
+
+(defvar *apply-stylesheet-counter* (make-profile-counter))
+(defvar *parse-stylesheet-counter* (make-profile-counter))
+(defvar *parse-xml-counter* (make-profile-counter))
+(defvar *unparse-xml-counter* (make-profile-counter))
+
+(defvar *profiling-enabled-p* nil)
+
+(defmacro with-profile-counter ((var) &body body)
+  `((lambda (fn)
+      (if (and *profiling-enabled-p* ,var)
+          (invoke-with-profile-counter fn ,var)
+          (funcall fn)))
+    (lambda () ,@body)))
+
 (defun/unparse doctype (name public-id system-id &optional internal-subset)
   (sax:start-dtd *sink* name public-id system-id)
   (when internal-subset
     (sax:unparsed-internal-subset *sink* internal-subset))
   (sax:end-dtd *sink*))
 
+(defstruct sink-element
+  local-name
+  uri
+  suggested-prefix
+  all-namespaces
+  new-namespaces
+  used-prefixes
+  attributes
+  actual-qname)
+
+(defstruct sink-attribute
+  local-name
+  uri
+  suggested-prefix
+  value)
+
 (defun maybe-emit-start-tag ()
   (let ((elt *current-element*))
     (when (and elt (not *start-tag-written-p*))
@@ -176,22 +208,6 @@
               (concatenate 'string "xmlns:" prefix))
    :value uri))
 
-(defstruct sink-element
-  local-name
-  uri
-  suggested-prefix
-  all-namespaces
-  new-namespaces
-  used-prefixes
-  attributes
-  actual-qname)
-
-(defstruct sink-attribute
-  local-name
-  uri
-  suggested-prefix
-  value)
-
 (defparameter *initial-unparse-namespaces*
   '(("" . "")
     ("xmlns" . #"http://www.w3.org/2000/xmlns/")
diff --git a/xslt.lisp b/xslt.lisp
index 4be88bf..2d0b4ff 100644
--- a/xslt.lisp
+++ b/xslt.lisp
@@ -150,20 +150,6 @@
 ;;;     (setf (gethash "" xpath::*extensions*) non-extensions)
 ;;;     (funcall fn)))
 
-(defstruct profile-counter calls run real)
-
-(defvar *apply-stylesheet-counter* (make-profile-counter))
-(defvar *parse-stylesheet-counter* (make-profile-counter))
-(defvar *parse-xml-counter* (make-profile-counter))
-(defvar *unparse-xml-counter* (make-profile-counter))
-
-(defmacro with-profile-counter ((var) &body body)
-  `((lambda (fn)
-      (if (and *profiling-enabled-p* ,var)
-          (invoke-with-profile-counter fn ,var)
-          (funcall fn)))
-    (lambda () ,@body)))
-
 
 ;;;; Helper functions and macros
 
@@ -1224,6 +1210,24 @@
                   (funcall (variable-value-thunk-setter var))))
               chains)))))
 
+(defstruct template
+  match-expression
+  compiled-pattern
+  name
+  import-priority
+  apply-imports-limit
+  priority
+  position
+  mode
+  mode-qname
+  params
+  body
+  n-variables
+  ;; for profiling output only:
+  unparsed-qname
+  stylesheet
+  base-uri)
+
 (defun parse-templates! (stylesheet <transform> env)
   (let ((i 0))
     (do-toplevel (<template> "template" <transform>)
@@ -1733,7 +1737,6 @@
         :mode mode)))))
 
 (defvar *apply-imports*)
-(defvar *profiling-enabled-p* nil)
 
 (defun apply-applicable-templates (ctx templates param-bindings finally)
   (labels ((apply-imports (&optional actual-param-bindings)
@@ -1875,24 +1878,6 @@
           (t
            (make-auto-detect-sink (make-combi-sink) method-key)))))))
 
-(defstruct template
-  match-expression
-  compiled-pattern
-  name
-  import-priority
-  apply-imports-limit
-  priority
-  position
-  mode
-  mode-qname
-  params
-  body
-  n-variables
-  ;; for profiling output only:
-  unparsed-qname
-  stylesheet
-  base-uri)
-
 (defun expression-priority (form)
   (let ((step (second form)))
     (if (and (null (cddr form))
