           redirectToLogin: ->
             @redirect "/login?return_to=#{@req.url}"
           logout: (fn) ->
-            @currentPerson.logout (error, resp) =>
-              @setCurrentPerson null
-              fn()
+            if @currentPerson?
+              @currentPerson.logout (error, resp) =>
+                @setCurrentPerson null
+                fn()
+            else fn()
           canEditTeam: (team) ->
             req.cookies.teamauthkey is team.authKey() or
               team.hasMember(@currentPerson) or

    throw e if e.errno != 2
    @next()

markdown = require 'markdown'
app.helpers {
  pluralize: (n, str) ->
    if n == 1

    else
      n + ' ' + str + 's'

  escapeURL: require('querystring').escape
  markdown: require('markdown').toHTML

  gravatar: (p, s) ->
    "<img src=\"http://www.gravatar.com/avatar/#{p.emailHash}?s=#{s || 40}&d=monsterid\" />"
