   document.title = title
   document.documentElement.replaceChild body, document.body
 
-  currentState = window.history.state
+  currentState = historyState
   triggerEvent 'page:change'
 
 
 reflectNewUrl = (url) ->
   if url isnt document.location.href
     referer = document.location.href
-    window.history.pushState { turbolinks: true, position: currentState.position + 1 }, '', url
+    historyPushState { turbolinks: true, position: currentState.position + 1 }, '', url
 
 rememberCurrentUrl = ->
-  window.history.replaceState { turbolinks: true, position: window.history.length - 1 }, '', document.location.href
+  historyReplaceState { turbolinks: true, position: window.history.length - 1 }, '', document.location.href
 
 rememberCurrentState = ->
-  currentState = window.history.state
+  currentState = historyState
 
 rememberInitialPage = ->
   unless initialized

  nonHtmlLink(link)  or remoteLink(link)      or noTurbolink(link)  or
  newTabClick(event)


browserSupportsPushState =
  window.history and window.history.pushState and window.history.replaceState

if browserSupportsPushState
  window.addEventListener 'popstate', (event) ->
    fetchHistory event.state if event.state?.turbolinks

  document.addEventListener 'click', handleClick,true

currentState = null
initialized  = false
referer = document.location.href
historyState = null

visit = (url) ->
  if browserSupportsPushState
