   (into []
         (map txn/hash-txn [(coinbase)])))
 
-(def mine? (atom true))
+(defonce mine? (atom true))
 (defn stop-miner! [] (reset! mine? false))
 
 (defn mine-block
   ([] (mine-block (generate-block (gather-transactions))))
   ([pending]
    (println "****** Will Mine Block: ******\n" pending "\n***************************")
-   (let [b (mine pending mine?)]
-     (println "****** Successfully Mined Block: ******\n" b "\n***************************")
-     (bc/add-block! b))))
+   (if-let [b (mine pending mine?)]
+     (do (println "****** Successfully Mined Block: ******\n" b "\n***************************")
+         (bc/add-block! b))
+     (println "didn't find coin, exiting"))))
 
 (defn run-miner! []
   (reset! mine? true)

(defn adjusted-target [blocks frequency]
  (let [times (map #(get-in % [:header :timestamp]) blocks)
        latest-target (get-in (last blocks) [:header :target])
        ratio (/ frequency (avg-spacing times))]
    (hex-string (bigint (* ratio
                           (hex->int latest-target))))))

(defn next-target

  ([block] (mine block (atom true)))
  ([block switch]
   (let [attempt (hashed block)]
     (when (= 0 (mod (get-in attempt [:header :nonce]) 1000000))
       (println "got to nonce: " (get-in attempt [:header :nonce])))
     (if (meets-target? attempt)
       attempt
       (if (not @switch)
         (do (println "exiting")
             nil)
         (recur (update-in block [:header :nonce] inc)
              switch))))))

(defn coinbase []
  {:inputs []
