     catch err
       console.error err
   locked = false
-proxy.addListener 'game.on.response', (method, path, body, postBody) ->
+
+handleProxyGameOnResponse = (method, path, body, postBody) ->
   # Important! Clone a copy of proxy objects!
   responses.push [method, path, JSON.parse(body), JSON.parse(postBody)]
   resolveResponses() if !locked
-proxy.addListener 'game.start', ->
+proxy.addListener 'game.on.response', handleProxyGameOnResponse
+
+handleProxyGameStart = ->
   window.dispatchEvent new Event 'game.start'
-proxy.addListener 'game.payitem', ->
+proxy.addListener 'game.start', handleProxyGameStart
+
+handleProxyGamePayitem = ->
   window.dispatchEvent new Event 'game.payitem'
-proxy.addListener 'network.error.retry', (counter) ->
+proxy.addListener 'game.payitem', handleProxyGamePayitem
+
+handleProxyNetworkErrorRetry = (counter) ->
   event = new CustomEvent 'network.error.retry',
     bubbles: true
     cancelable: true
     detail:
       counter: counter
   window.dispatchEvent event
-proxy.addListener 'network.invalid.code', (code) ->
+proxy.addListener 'network.error.retry', handleProxyNetworkErrorRetry
+
+handleProxyNetworkInvalidCode = (code) ->
   event = new CustomEvent 'network.invalid.code',
     bubbles: true
     cancelable: true
     detail:
       code: code
   window.dispatchEvent event
-proxy.addListener 'network.error', ->
+proxy.addListener 'network.invalid.code', handleProxyNetworkInvalidCode
+
+handleProxyNetworkError = ->
   window.dispatchEvent new Event 'network.error'
+proxy.addListener 'network.error', handleProxyNetworkError
+
+window.addEventListener 'unload', ->
+  proxy.removeListener 'game.on.request', handleProxyGameOnRequest
+  proxy.removeListener 'game.on.response', handleProxyGameOnResponse
+  proxy.removeListener 'game.start', handleProxyGameStart
+  proxy.removeListener 'game.payitem', handleProxyGamePayitem
+  proxy.removeListener 'network.error.retry', handleProxyNetworkErrorRetry
+  proxy.removeListener 'network.invalid.code', handleProxyNetworkInvalidCode
+  proxy.removeListener 'network.error', handleProxyNetworkError
      path: path
      body: body
  window.dispatchEvent event

start2Version = 0
initStart2Value = ->

  s += if isDarkTheme then ' dark' else ' light'


handleProxyGameOnRequest = (method, path, body) ->
  # Important! Clone a copy of proxy objects!
  body = JSON.parse body
  event = new CustomEvent 'game.request',
