   revive =(objRef, callback)->
     unless objRef?.constructorName? and objRef.id? then callback null
     else KD.remote.cacheable objRef.constructorName, objRef.id, callback
-
-  isWindowLoaded = -> document.readyState is 'complete'
 
   constructor:(routes)->
 


  back:-> if @visitedRoutes.length <= 1 then @clear() else history.back()

  startListening:->
    return no  if @isListening # make this action idempotent
    @isListening = yes

    if isWindowLoaded()
      @blockPopstateIfWindowLoaded = no
    else
      @blockPopstateIfWindowLoaded = yes
      window.addEventListener 'load', @bound 'handleWindowLoad'

    # we need to add a listener to the window's popstate event:
    window.addEventListener 'popstate', @bound "popState"

    return yes

  stopListening:->
    return no  unless @isListening # make this action idempotent

    @startListening()

  popState:(event)->
    revive event.state, (err, state)=>
      return KD.showError err  if err
      @handleRoute "#{location.pathname}#{location.search}",
        shouldPushState   : no
        state             : state

  clear:(route = '/', replaceState = yes)->
    delete @userRoute # TODO: i hope deleting the userRoute here doesn't break anything... C.T.
