         post_vertices_offset (process_vertices buffer
                                                post_normal_offset
                                                (:vertices facet))]
-    pad buffer post_vertices_offset 2))
+    (pad buffer post_vertices_offset 2)))
 
 (defn calculate-file-size
   [num_facets]
   (+ stl-file/HEADER_LENGTH (* num_facets stl-file/BYTES_PER_FACET)))
+
+(defn process-facets [buffer offset facets] 
+                               (if (seq facets)
+                                 (let [[f & fs] facets
+                                       new-offset (write-facet buffer offset f)]
+                                   (recur buffer new-offset fs))
+                                 offset))
 
 (defn write-stl
   [stl-seq ^String filename]

(defn write-header
  [buffer count]
  (pad buffer 0 stl-file/MESSAGE_LENGTH)
  (.putInt buffer 0 count)
  stl-file/HEADER_LENGTH)

(defn write-facet

                                             offset
                                             length)
                               (.order ByteOrder/LITTLE_ENDIAN))
          post-header-offset (write-header buffer num_facets)]
      (process-facets buffer post-header-offset stl-seq))))


