   stop: () ->
     clearInterval @interval if @interval
 
+  updateHistory: (history) ->
+    validateHistory history
+    @history = history
+    @history = @history.slice Math.max(@history.length-@historysize, 0)
+    debug 'history length', @history.length
+
   nextState: (err, queues, details) ->
     state = nextState @config, @history, queues, details
-    @history.push state
-    @history = @history.slice Math.max(@history.length-@historysize, 0)
-    debug 'history length', @history.length
+    history = @history.concat [ state ]
+    @updateHistory history
     return state
 
   runOnceInternal: (callback) ->

    return callback err, state if err
    return callback null, state

class Governor extends EventEmitter
  constructor: (c) ->
    @config = c

  start: () ->
    runFunc = () =>
      @runOnce (err, state) =>
        # error and state are emitted,

    interval = setInterval runFunc, @pollinterval
    runFunc() # do first iteration right now
