           msg.send "Canceled build #{response.build_num} for #{project} [#{response.branch}]"
 
   robot.respond /circle clear (.*)/i, (msg) ->
+    unless checkToken(msg)
+      return
     project = escape(msg.match[1])
     msg.http("#{endpoint}/project/#{project}/build-cache?circle-token=#{process.env.HUBOT_CIRCLECI_TOKEN}")
       .headers("Accept": "application/json")
       .del('{}') handleResponse msg, (response) ->
           msg.send "Cleared build cache for #{project}"
-
-  handleResponse = (msg, handler) ->
-    (err, res, body) ->
-      switch res.statusCode
-        when 404
-          msg.send "I couldn't find what you were looking for"
-        when 401
-          msg.send 'Not authorized. Did you set HUBOT_CIRCLECI_TOKEN?'
-        when 500
-          msg.send 'Yikes!  I turned that circle into a square'
-        when 200
-          response = JSON.parse(body)
-          handler response
-        else
-          msg.send "Hmm.  I don't know how to process that CircleCI response: #{res.statusCode}"
 
   robot.router.post "/hubot/circle", (req, res) ->
     query = querystring.parse url.parse(req.url).query

            msg.send "Current status: #{formatBuildStatus(currentBuild)}"

  robot.respond /circle last (\S*)\s*(\S*)/i, (msg) ->
    project = escape(msg.match[1])
    branch = if msg.match[2] then escape(msg.match[2]) else 'master'
    msg.http("#{endpoint}/project/#{project}/tree/#{branch}?circle-token=#{process.env.HUBOT_CIRCLECI_TOKEN}")

              msg.send "Last build status for #{project} [#{branch}]: unknown"

  robot.respond /circle retry (.*) (.*)/i, (msg) ->
    unless checkToken(msg)
      return
    project = escape(msg.match[1])
    
    unless msg.match[2]?
      msg.send "I can't retry without a build number"
      return
    build_num = escape(msg.match[2])
