         handler get_path_val(@state, var_path), undefined
     
     resetState: (new_state) =>
+        old_state = @state
+        @state = new_state
         for [var_path, handler] in @listeners
-            new_val = get_path_val new_state, var_path
-            old_val = get_path_val @state, var_path
+            new_val = get_path_val @state, var_path
+            old_val = get_path_val old_state, var_path
             if _.isEqual new_val, old_val
                 continue
             # TODO: Don't stop processing on exception
             handler(new_val, old_val)
-        @state = new_state
 
 # TODO: Hack for old browsers?
 get_state_string = ->

set_state_string = (new_hash, history=false) ->
    if new_hash
        new_hash = '?' + new_hash
    if history
        History.pushState null, null, new_hash
    else


deep_extend = (target, update) ->
    for subname, value of update
        if not value?
            delete target[subname]
            continue
        if not _.isObject value
            target[subname] = value
            continue
