 
   battle.once 'ratingsUpdated', =>
     for player in battle.players
-      @checkAndAwardAchievements(server, player)
+      @checkAndAwardAchievements(server, player.id, player.ratingKey)
 
 
 # Returns the achievements a player is eligible for, including already earned ones
-# id is the rating key used to identify the player
-checkAchievements = (id, next) ->
-  ratings.getRatio id, (err, ratio) ->
-    ratings.getStreak id, (err, streak) ->
+checkAchievements = (ratingKey, next) ->
+  ratings.getRatio ratingKey, (err, ratio) ->
+    ratings.getStreak ratingKey, (err, streak) ->
       achievements = ACHIEVEMENTS.filter((o) -> o.conditionFn(ratio, streak))
 
       # Send everything except the conditionFn attribute

    do (achievement) -> (callback) ->
      request.post {
        url: "https://www.pokebattle.com/api/v1/achievements/"
        json: { user: playerName, achievement: achievement.name }
      }, (err, res, data) ->
        status = "success"
        status = "error"  if err


# Checks what achievements a player is eligible for
# The achievements are then awarded to the player
# Note: In the current implementation, playerId is actually a name
@checkAndAwardAchievements = (server, playerId, ratingKey, next = ->) ->
  checkAchievements ratingKey, (err, achievements) ->
    return next(err) if err
    return next() if achievements.length == 0

    filterEarned playerId, achievements, (err, achievements) ->
      return next(err) if err
      return next() if achievements.length == 0

      notifyServer playerId, achievements, (err, byStatus) ->
        return next(err) if err

        # TODO: Handle errors, probably add them to some queue to retry
