 
 Aether.addGlobal 'Vector', require '../app/lib/world/vector'
 Aether.addGlobal '_', _
-
+i = 0
 transpileLevelSession = (sessionID, cb) ->
-  query = LevelSession.findOne("_id": sessionID).select("submittedCode submittedCodeLanguage").lean()
+  query = LevelSession.findOne("_id": sessionID).select("team teamSpells submittedCode submittedCodeLanguage").lean()
   query.exec (err, session) ->
     if err then return cb err
     submittedCode = session.submittedCode
     unless session.submittedCodeLanguage
       throw "SUBMITTED CODE LANGUAGE DOESN'T EXIST"
     else
-      console.log "Transpiling code for session #{session._id} in language #{session.submittedCodeLanguage}"
+      console.log "Transpiling code for session #{i++} #{session._id} in language #{session.submittedCodeLanguage}"
     transpiledCode = {}
     #console.log "Updating session #{sessionID}"
     for thang, spells of submittedCode
       transpiledCode[thang] = {}
       for spellID, spell of spells
+        spellName = thang + "/" + spellID
 
+        if session.teamSpells and not (spellName in session.teamSpells[session.team]) then continue
+        #console.log "Transpiling spell #{spellName}"
         aetherOptions =
           problems: {}
-          language: session.submittedCodeLanguage 
+          language: session.submittedCodeLanguage
           functionName: spellID
           functionParameters: []
           yieldConditionally: spellID is "plan"

      throw err if err

serverSetup.connectToDatabase()
transpileLadderSessions()

    levelSessionIDs = _.pluck levelSessions, "_id"
    async.eachSeries levelSessionIDs, transpileLevelSession, (err) ->
      if err then return cb err
      return cb null


transpileLadderSessions = ->
