 
       return true
     
-  @letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser: (winnerId, loserId) ->
-    $.each window.matches, (index, match) ->  
-      matchOfWinner = $.inArray(winnerId, match['competitors'])
-      return true if matchOfWinner == -1
-      
-      matchCompetitorsWhichIncludeLoser = jQuery.map(match['competitors'], (c) ->
-        if $.inArray(c, window.Voluntary.DomManipulation.CompetitiveList.defeatedCompetitorsByCompetitor(loserId)) > -1
+  letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser: (winnerId, loserId) ->
+    @defeatedCompetitorsByCompetitor[loserId] ||= []
+    
+    $.each window.matches, (index, match) =>  
+      return true if match['winner_competitor'] == winnerId || $.inArray(winnerId, match['competitors']) == -1
+      
+      matchCompetitorsWhichIncludeLoser = jQuery.map(match['competitors'], (c) =>
+        if $.inArray(c, @defeatedCompetitorsByCompetitor[loserId]) > -1
           return c
       )
         
-      return true if match['winner_competitor'] == winnerId || matchCompetitorsWhichIncludeLoser.length == 0
-        
-      otherLoserId = window.Voluntary.DomManipulation.CompetitiveList.otherCompetitorOfMatch(match, winnerId)
-      
-      window.matchesWon[winnerId] ||= 0
-      window.matchesWon[winnerId] = window.matchesWon[winnerId] + 1
-      
-      unless match['winner_competitor'] == undefined
-        window.Voluntary.DomManipulation.CompetitiveList.changeCompetitorsComparisonResult(winnerId, otherLoserId)
-        
-      window.Voluntary.DomManipulation.CompetitiveList.appointWinnerOfMatch(index, winnerId, loserId, match['winner_competitor'] == undefined)
+      return true if matchCompetitorsWhichIncludeLoser.length == 0
+        
+      otherLoserId = @otherCompetitorOfMatch(match, winnerId)
+      
+      @changeCompetitorsComparisonResult(winnerId, otherLoserId) unless match['winner_competitor'] == undefined
+        
+      @appointWinnerOfMatch(index, winnerId, otherLoserId, match['winner_competitor'] == undefined)
       window.matches[index]['winner_competitor'] = winnerId
-      console.log 'auto_winner through @letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser: ' + JSON.stringify([winnerId, loserId])
       window.matches[index]['auto_winner'] = true
       
-  @changeCompetitorsComparisonResult: (winnerId, loserId) ->
-    window.matchesWon[loserId] = window.matchesWon[loserId] - 1
-    window.outmatchedCompetitorsByCompetitor[winnerId] ||= []
-    window.outmatchedCompetitorsByCompetitor[winnerId] = window.Voluntary.DomManipulation.CompetitiveList.removeItemFromArray(window.outmatchedCompetitorsByCompetitor[winnerId], loserId)
-    window.defeatedCompetitorsByCompetitor[loserId] = window.Voluntary.DomManipulation.CompetitiveList.removeItemFromArray(window.outmatchedCompetitorsByCompetitor[loserId], winnerId)
-    
-  @defeatedCompetitorsByCompetitor: (competitorId) ->
-    window.defeatedCompetitorsByCompetitor[competitorId] ||= []
-      
-    return window.defeatedCompetitorsByCompetitor[competitorId]
-
-  @otherCompetitorOfMatch: (match, competitorId) ->
+  changeCompetitorsComparisonResult: (winnerId, loserId) ->
+    @outmatchedCompetitorsByCompetitor[winnerId] ||= []
+    @outmatchedCompetitorsByCompetitor[winnerId] = @removeItemFromArray(@outmatchedCompetitorsByCompetitor[winnerId], loserId)
+    @defeatedCompetitorsByCompetitor[loserId] = @removeItemFromArray(@outmatchedCompetitorsByCompetitor[loserId], winnerId)
+    
+  getDefeatedCompetitorsByCompetitor: (competitorId) ->
+    @defeatedCompetitorsByCompetitor[competitorId] ||= []
+      
+    return @defeatedCompetitorsByCompetitor[competitorId]
+
+  otherCompetitorOfMatch: (match, competitorId) ->
     otherCompetitors = jQuery.map(match['competitors'], (c) ->
       if c != competitorId
         return c
     )
     return otherCompetitors[0]
 
-  @appointWinnerOfMatchByInput: () ->
+  appointWinnerOfMatchByInput: () ->
     winnerId = parseInt($("input[name='winner']:checked").val())
-    loserId = window.Voluntary.DomManipulation.CompetitiveList.otherCompetitorOfMatch(window.currentMatch, winnerId)
-    
-    window.Voluntary.DomManipulation.CompetitiveList.appointWinnerOfMatch(window.currentMatchIndex, winnerId, loserId, true)
-    
-    unless window.Voluntary.DomManipulation.CompetitiveList.nextMatch()
-      window.Voluntary.DomManipulation.CompetitiveList.sortByMostMatchesWon()
+    loserId = @otherCompetitorOfMatch(@currentMatch, winnerId)
+    
+    @appointWinnerOfMatch(@currentMatchIndex, winnerId, loserId, true)
+    
+    unless @nextMatch()
+      @sortByMostWins()
       $('#bootstrap_modal').modal('hide')
       
-  @appointWinnerOfMatch: (matchIndex, winnerId, loserId, decrementMatchesLeft) ->
+  appointWinnerOfMatch: (matchIndex, winnerId, loserId, decrementMatchesLeft) ->
     window.matches[matchIndex]['winner_competitor'] = winnerId
-    window.matchesLeft = window.matchesLeft - 1 if decrementMatchesLeft
-    
-    window.Voluntary.DomManipulation.CompetitiveList.incrementMatchesWon(winnerId, loserId)
-    window.Voluntary.DomManipulation.CompetitiveList.letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser(winnerId, loserId)
-    window.Voluntary.DomManipulation.CompetitiveList.letOutMatchedCompetitorsOfWinnerWinAgainstLoser(winnerId, loserId)
-    
-  @letOutMatchedCompetitorsOfWinnerWinAgainstLoser: (winnerId, loserId) ->
-    $.each window.Voluntary.DomManipulation.CompetitiveList.outmatchedCompetitorsByCompetitor(winnerId), (index, competitorId) ->
-      window.Voluntary.DomManipulation.CompetitiveList.letCompetitorWinMatchAgainstOtherCompetitor(competitorId, loserId)
-
-  @outmatchedCompetitorsByCompetitor: (competitorId) ->
-    window.outmatchedCompetitorsByCompetitor[competitorId] ||= []
-      
-    return window.outmatchedCompetitorsByCompetitor[competitorId]
-
-  @letCompetitorWinMatchAgainstOtherCompetitor: (winnerId, loserId) ->
+    @matchesLeft = @matchesLeft - 1 if decrementMatchesLeft
+    
+    @updateDefeatedAndOutmatchedCompetitorsByCompetitor(winnerId, loserId)
+    @letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser(winnerId, loserId)
+    @letOutMatchedCompetitorsOfWinnerWinAgainstLoser(winnerId, loserId)
+    
+  letOutMatchedCompetitorsOfWinnerWinAgainstLoser: (winnerId, loserId) ->
+    @outmatchedCompetitorsByCompetitor[winnerId] ||= []
+    
+    $.each @outmatchedCompetitorsByCompetitor[winnerId], (index, competitorId) =>
+      @letCompetitorWinMatchAgainstOtherCompetitor(competitorId, loserId)
+      
+    return @outmatchedCompetitorsByCompetitor[competitorId]
+
+  letCompetitorWinMatchAgainstOtherCompetitor: (winnerId, loserId) ->
+    $.each window.matches, (index, match) =>
+      if $.inArray(winnerId, match['competitors']) > -1 && $.inArray(loserId, match['competitors']) > -1 && match['winner_competitor'] != winnerId
+        window.matches[index]['auto_winner'] = true
+        @changeCompetitorsComparisonResult(winnerId, loserId) unless match['winner_competitor']  == undefined
+        @appointWinnerOfMatch(index, winnerId, loserId, match['winner_competitor']  == undefined)
+        
+        return false
+
+  updateDefeatedAndOutmatchedCompetitorsByCompetitor: (winnerId, loserId) ->
+    @defeatedCompetitorsByCompetitor[winnerId] ||= []
+    @defeatedCompetitorsByCompetitor[winnerId].push loserId  
+     
+    @outmatchedCompetitorsByCompetitor[loserId] ||= []
+    @outmatchedCompetitorsByCompetitor[loserId].push winnerId
+     
+  cancelTournament: ->
+    @sortByMostWins()
+    $('#bootstrap_modal').modal('hide')
+      
+  sortByMostWins: ->
+    winsByCompetitor = {}
+    
+    $.each @competitors, (index, competitorId) =>
+      winsByCompetitor[competitorId] = 0
+
     $.each window.matches, (index, match) ->
-      if $.inArray(winnerId, match['competitors']) > -1 && $.inArray(loserId, match['competitors']) > -1 && match['winner_competitor'] != winnerId
-        console.log 'auto_winner through @letCompetitorWinMatchAgainstOtherCompetitor: ' + JSON.stringify([winnerId, loserId])
-        window.matches[index]['auto_winner'] = true
-        window.Voluntary.DomManipulation.CompetitiveList.changeCompetitorsComparisonResult(winnerId, loserId) unless match['winner_competitor']  == undefined
-        window.Voluntary.DomManipulation.CompetitiveList.appointWinnerOfMatch(index, winnerId, loserId, match['winner_competitor']  == undefined)
-        
-        return false
-
-  @incrementMatchesWon: (winnerId, loserId) ->
-    window.matchesWon[winnerId] ||= 0
-    window.matchesWon[winnerId] = window.matchesWon[winnerId] + 1
-    
-    window.Voluntary.DomManipulation.CompetitiveList.defeatedCompetitorsByCompetitor(winnerId)  
-    window.defeatedCompetitorsByCompetitor[winnerId] ||= []
-    window.defeatedCompetitorsByCompetitor[winnerId].push loserId  
-    
-    window.Voluntary.DomManipulation.CompetitiveList.outmatchedCompetitorsByCompetitor(loserId)  
-    window.outmatchedCompetitorsByCompetitor[loserId] ||= []
-    window.outmatchedCompetitorsByCompetitor[loserId].push winnerId
-     
-  @cancelTournament: ->
-    window.Voluntary.DomManipulation.CompetitiveList.sortByMostMatchesWon()
-    $('#bootstrap_modal').modal('hide')
-      
-  @sortByMostMatchesWon: ->
-    $.each window.competitors, (index, competitorId) ->
-      window.matchesWon[competitorId] ||= 0
-      $('#competitor_' + competitorId).data('wins', window.matchesWon[competitorId])
+      winsByCompetitor[match['winner_competitor']] += 1
+    
+    $.each Object.keys(winsByCompetitor), (index, competitorId) ->
+      $('#competitor_' + competitorId).data 'wins', winsByCompetitor[competitorId]
       
     $wrapper = $('.competitive_list')
     

      competitorStrings = []
      i = 0
      
      $.each window.currentMatch['competitors'], (index, competitorId) ->
        competitorDomElement = $('#competitor_' + competitorId)
        checked = ' checked="checked"'
        checked = '' if i == 1
        radioButtons.push ('<input type="radio" ' + checked + ' name="winner" value="' + competitorId + '" style="position:relative; top:-5px "/>')
        
        if window.competitiveListOptions['competitor_name_proc'] == undefined || $(competitorDomElement).find('.competitor_name').data('proc-argument') == undefined
          competitorStrings.push $(competitorDomElement).find('.competitor_name').html()  
        else
          competitorStrings.push window.competitiveListOptions['competitor_name_proc']($(competitorDomElement).find('.competitor_name').data('proc-argument'))
          
        i += 1
        

    $.each $('.competitive_list li'), (index, element) ->
      positions[currentPosition] = $(element).data('id')
      $(element).data('position', currentPosition)  
      $(element).find('.competitor_position').html(currentPosition)
      currentPosition += 1  
      
    data = { _method: 'put', positions: positions, matches: JSON.stringify(window.matches) }  
    $.post $('.competitive_list').data('update-all-positions-path'), data   