     width: b.width
     height: b.height
     realClose: true
-  window.poiStatsWindow = newWindow
+  ps = window.plugin.poiStats
+  ps.window = newWindow
   newWindow.setMinimumSize 600, 425
   newWindow.on 'move', handleWindowMoveResize
   newWindow.on 'resize', handleWindowMoveResize
-  newWindow.on 'closed', -> window.poiStatsWindow = null
+  newWindow.on 'close', ->
+    if ps.bounds?
+      config.set 'plugin.PoiStatistics.bounds', ps.bounds
+  newWindow.on 'closed', ->
+    ps.window = ps.bounds = null
   if process.env.DEBUG?
     window.log 'Poi Stats started.'
     newWindow.openDevTools

i18n.setLocale(window.language)


window.poiStatsWindow = null

handleWindowMoveResize = ->
  b1 = window.poiStatsWindow.getBounds()
  # console.log "Moved to: #{JSON.stringify(b1)}"
  setTimeout(( ->
    b2 = window.poiStatsWindow.getBounds()
    if JSON.stringify(b2) == JSON.stringify(b1)
      config.set 'plugin.PoiStatistics.bounds', b2
      # console.log "   Saved:  #{JSON.stringify(b2)}"
  ), 5000)

initialPoiStatsWindow = ->
  defaultBounds = {x: 0, y: 0, width: 800, height: 750}

  version: '1.2.0'
  description: __ 'PluginDesc'
  handleClick: ->
    if window.plugin.poiStats.window?
      window.plugin.poiStats.window.show()
    else
      initialPoiStatsWindow()
