 
   robot.brain.on 'loaded', () ->
     loaded = true
+    robot.brain.resetSaveInterval(save_interval)
+    store_current_brain()
+
+  robot.brain.on 'save', () ->
     store_current_brain()
 
   robot.brain.on 'close', ->
-    clearInterval intervalId
     store_current_brain()

#   "aws2js": "0.7.10"
#
# Configuration:
#   HUBOT_S3_BRAIN_ACCESS_KEY_ID
#   HUBOT_S3_BRAIN_SECRET_ACCESS_KEY
#   HUBOT_S3_BRAIN_BUCKET
#
# Commands:
#
# Notes:
#   It's highly recommended to use an IAM account explicitly for this purpose
#   https://console.aws.amazon.com/iam/home?
#   A sample S3 policy for a bucket named Hubot-Bucket would be

  store_current_brain = () ->
    store_brain robot.brain.data

  s3.get brain_dump_path, 'buffer', (err, response) ->
    # unfortunately S3 gives us a 403 if we have access denied OR
    # the file is simply missing, so no way of knowing if IAM policy is bad
