             (log/info "Submitting batch")
             ;; Submit new jobs
             (doseq [job submission-batch]
-              (org.joda.time.DateTimeUtils/setCurrentMillisFixed (inc (.getTime (tc/to-date (t/now)))))
+              (DateTimeUtils/setCurrentMillisFixed (inc (.getTime (tc/to-date (t/now)))))
               (submit-job mesos-datomic-conn job))
             ;; Ensure peer has acknowledged the new jobs
             (when (seq submission-batch)
               (poll-until #(d/q '[:find ?j .
-                                      :in $ ?t
-                                      :where
-                                      [?j :job/submit-time ?t]]
-                                    (d/db mesos-datomic-conn)
-                                    ;; This relies on
-                                    ;; 1. Time is controlled
-                                    ;; 2. We increment time for each job submitted
-                                    (tc/to-date (t/now)))
-                        50
-                        60000))
+                                  :in $ ?t
+                                  :where
+                                  [?j :job/submit-time ?t]]
+                                (d/db mesos-datomic-conn)
+                                ;; This relies on
+                                ;; 1. Time is controlled
+                                ;; 2. We increment time for each job submitted
+                                (tc/to-date (t/now)))
+                          50
+                          60000))
             (log/info "Batch submission complete")
 
             ;; Request for jobs that are complete to have cook be notified
             (log/info "Send completion status to scheduler")
-            (org.joda.time.DateTimeUtils/setCurrentMillisFixed (inc (.getTime (tc/to-date (t/now)))))
+            (DateTimeUtils/setCurrentMillisFixed (inc (.getTime (tc/to-date (t/now)))))
             (async/>!! complete-trigger-chan flush-complete-chan)
             (async/<!! flush-complete-chan)
 
             ;; Ensure mesos and cook state of running jobs matches
             (poll-until #(= (set (map (comp str :instance/task-id)
-                                     (util/get-running-task-ents (d/db mesos-datomic-conn))))
+                                      (util/get-running-task-ents (d/db mesos-datomic-conn))))
                             (set (map str
-                                     (keys (:task-id->task @state-atom)))))
-                       50
-                       60000
-                       #(let [cook-tasks (set (map (comp str :instance/task-id)
-                                                   (util/get-running-task-ents (d/db mesos-datomic-conn))))
-                              mesos-tasks (set (map str
-                                                    (keys (:task-id->task @state-atom))))]
-                          {:running-tasks-ents (count cook-tasks)
-                           :tasks-in-mesos (count mesos-tasks)
-                           :cook-minus-mesos (count (clojure.set/difference cook-tasks mesos-tasks))
-                           :mesos-minus-cook (count (clojure.set/difference mesos-tasks cook-tasks))})
-                       )
+                                      (keys (:task-id->task @state-atom)))))
+                        50
+                        60000
+                        #(let [cook-tasks (set (map (comp str :instance/task-id)
+                                                    (util/get-running-task-ents (d/db mesos-datomic-conn))))
+                               mesos-tasks (set (map str
+                                                     (keys (:task-id->task @state-atom))))]
+                           {:running-tasks-ents (count cook-tasks)
+                            :tasks-in-mesos (count mesos-tasks)
+                            :cook-minus-mesos (count (clojure.set/difference cook-tasks mesos-tasks))
+                            :mesos-minus-cook (count (clojure.set/difference mesos-tasks cook-tasks))}))
             (log/info "Completion statuses sent")
 
             ;; Request rank occurs
             (log/info "Starting rank")
-            (org.joda.time.DateTimeUtils/setCurrentMillisFixed (inc (.getTime (tc/to-date (t/now)))))
+            (DateTimeUtils/setCurrentMillisFixed (inc (.getTime (tc/to-date (t/now)))))
             (async/>!! ranker-trigger-chan rank-complete-chan)
             (async/<!! rank-complete-chan)
             (log/info "Rank complete")
 
-            (async/>!! optimizer-trigger-chan optimizer-complete-chan)
-            (async/<!! optimizer-complete-chan)
+            (when (> time-ms-since-last-optimizer-call time-ms-between-optimizer-calls)
+              (log/info "Starting optimizer")
+              (async/>!! optimizer-trigger-chan optimizer-complete-chan)
+              (async/<!! optimizer-complete-chan)
+              (log/info "Optimizer complete"))
 
             ;; Match
             (log/info "Starting match")
-            (org.joda.time.DateTimeUtils/setCurrentMillisFixed (inc (.getTime (tc/to-date (t/now)))))
+            (DateTimeUtils/setCurrentMillisFixed (inc (.getTime (tc/to-date (t/now)))))
             (async/>!! offer-trigger-chan send-offers-complete-chan)
             (async/<!! send-offers-complete-chan)
             (async/>!! matcher-trigger-chan match-complete-chan)
             (async/<!! match-complete-chan)
             ;; Ensure the launch has been processed by mesos
             (poll-until #(every? :instance/mesos-start-time
-                                (util/get-running-task-ents (d/db mesos-datomic-conn)))
+                                 (util/get-running-task-ents (d/db mesos-datomic-conn)))
                         50
                         60000)
             (log/info "Match complete")
 
             ;; Rebalance
-            (when (> time-ms-since-last-rebalancer (:time-ms-between-rebalancing config))
+            (when (> time-ms-since-last-rebalancer time-ms-between-rebalancing)
               (log/info "Starting rebalance")
-              (org.joda.time.DateTimeUtils/setCurrentMillisFixed (inc (.getTime (tc/to-date (t/now)))))
+              (DateTimeUtils/setCurrentMillisFixed (inc (.getTime (tc/to-date (t/now)))))
               (async/>!! rebalancer-trigger-chan rebalancer-complete-chan)
               (async/<!! rebalancer-complete-chan)
               (log/info "Rebalance complete"))
-            
+
             ;; Periodically perform full gc under hypothesis that holding onto
             ;; lot of memory is causing problems
             (when (> (rand) 0.9)

            (when (seq trace)
              (recur (drop (count submission-batch) trace)
                     (+ simulation-time cycle-step-ms)
                     (if (> time-ms-since-last-rebalancer (:time-ms-between-rebalancing config))
                       0
                       (+ time-ms-since-last-rebalancer cycle-step-ms))))))
        (println "count of jobs submitted " (count (d/q '[:find ?e
                                                          :where
                                                          [?e :job/uuid _]]

  "Returns a job that can be used in the trace"
  [run-time-ms submit-time-ms &
   {:keys [user uuid command ncpus memory name retry-count max-runtime priority job-state submit-time custom-executor? gpus group committed?
           disable-mea-culpa-retries]
    :or {user (System/getProperty "user.name")
         uuid (d/squuid)
         committed? true
