     pagerDutyGet msg, "/schedules", query, (json) ->
       schedule = null
       # Single result returned
-      if json.schedules and json.schedules.length == 1
+      if json?.schedules?.length == 1
         schedule = json.schedules[0]
 
       # Multiple results returned and one is exact
-      if json.schedules and json.schedules.length > 1
+      if json?.schedules?.length > 1
         matchingExactly = json.schedules.filter (s) ->
           s.name == q
         if matchingExactly.length == 1

    email = msg.match[1]
    msg.message.user.pagerdutyEmail = email
    msg.send "Okay, I'll remember your PagerDuty email is #{email}"

  # Assumes your Campfire usernames and PagerDuty names are identical
  robot.respond /pager( me)? (.+) (\d+)$/i, (msg) ->
    campfireUserToPagerDutyUser msg, msg.message.user, (user) ->

      userId = user.id
      return unless userId

      if !msg.match[2] || msg.match[2] == 'me'
        msg.reply "Please specify a schedule with 'pager me ops 60.'' Use 'pager schedules' to list all schedules."
        return

      withScheduleMatching msg, msg.match[2], (matchingSchedule) ->

        return unless matchingSchedule.id

        start     = moment().format()
        minutes   = parseInt msg.match[3]
        end       = moment().add('minutes', minutes).format()
        override  = {
          'start':     start,
          'end':       end,
          'user_id':   userId
        }
        withCurrentOncall msg, matchingSchedule, (old_username, schedule) ->
          data = { 'override': override }
          pagerDutyPost msg, "/schedules/#{schedule.id}/overrides", data, (json) ->
            if json.override
              start = moment(json.override.start)
              end = moment(json.override.end)
              msg.send "Rejoice, #{old_username}! #{json.override.user.name} has the pager on #{schedule.name} until #{end.format()}"

  robot.respond /(pager|major)( me)? incident (.*)$/, (msg) ->
    pagerDutyIncident msg, msg.match[3], (incident) ->

            , 5000

  robot.respond /(?:pager|major)(?: me)? ack(?:nowledge)? (.+)$/i, (msg) ->
    msg.finish()
    incidentNumbers = parseIncidentNumbers(msg.match[1])

    # only acknowledge triggered things, since it doesn't make sense to re-acknowledge if it's already in re-acknowledge
