       console.log(promise)
       promise.then (res) ->
         console.log("GOT RES:", res)
-        $scope.parseResults(res.data)
-
+        parseResults(res.data)
+
+    # This function will return the larger number of results of the
+    # two types. So if there are more volumes than parties, it returns
+    # the number of volumes.
     $scope.maxResults = ->
       return Math.max($scope.volumeCount, $scope.partyCount)
 
     #################################
-    # Parse results, the main workhorse function
+    # Parse results, the main workhorse function.
+    # This function is called after each search and is used to set
+    # all of the params for use in the html.
     # ##############################
-    $scope.parseResults = (res) ->
+    parseResults = (res) ->
       if res == "null"
         $scope.query = "*"
-        $scope.search()
+        search()
         return
       # if !$scope.query? or !$scope.query or $scope.query == "" or $scope.query == "null" or $scope.query == "false" or $scope.query == "undefined"
         # $scope.query = "*"
       console.log("query before anything:", $scope.query)
       console.log("RES:", res)
-      $scope.partyResults = $scope.getResults("party", res)
-      $scope.volumeResults = $scope.getResults("volume", res)
-
-      $scope.partyCount = $scope.getTypeCounts("party", res)
-      $scope.volumeCount = $scope.getTypeCounts("volume", res)
-
-      $scope.suggestedQuery = $scope.getCollation(res)
-
+      $scope.partyResults = getResults("party", res)
+      $scope.volumeResults = getResults("volume", res)
+
+      # Set the number of parties and volumes returned.
+      $scope.partyCount = getTypeCounts("party", res)
+      $scope.volumeCount = getTypeCounts("volume", res)
+
+      # If there is a suggested query, extract it.
+      $scope.suggestedQuery = getSuggestedQuery(res)
+
+      # Include the number of returned results in the type display.
       $scope.typeDisplay = [$scope.partyDisplayStr + " (" + ($scope.partyCount || 0) + ")",
         $scope.volumeDisplayStr + " (" + ($scope.volumeCount || 0) + ")"]
 
       console.log("PARTY RESULTS", $scope.partyResults)
       console.log("SUGGESTED QUERY", $scope.suggestedQuery)
 
-      if $scope.partyCount
-        $scope.affiliations = (c.party_affiliation_s for c in $scope.partyResults.docs)
-      else
-        $scope.affiliations = ["No people found"]
+      # Code for extracting user affiliations for filtering, unused.
+      # if $scope.partyCount
+        # $scope.affiliations = (c.party_affiliation_s for c in $scope.partyResults.docs)
+      # else
+        # $scope.affiliations = ["No people found"]
 
       $scope.totalCount = $scope.partyCount + $scope.volumeCount
 
+
+      # Set up pagination
       $scope.minPage = 1
       $scope.maxPage = 1 + ($scope.maxResults() / ($scope.limit + 1))
       pageRange = []

      $scope.originalQuery = params.query
    console.log(results)
    $scope.offset = parseInt($location.search().offset, 10) || 0
    $scope.parseResults(results)

    console.log(results)


    $scope.selectedType = ""
    $scope.selectedVolume = ""
    $scope.selectedFilter = ""

    # Array that holds the names of the types the user
    # can filter by (volume, party)
    $scope.typeDisplay = []

    # Array that holds the current available filters
    # for the selected type.
    $scope.filterDisplay = []

    # These hold the current number of returned values
    # for each type. These are all set in parseResults.
    $scope.volumeCount = 0
    $scope.partyCount = 0
    $scope.totalCount = 0

    $scope.selectSessionStr = "Volumes w/ Sessions"
    $scope.selectHighlightStr = "Volumes w/ Highlights"
    $scope.selectPeopleFilters = ["All", "Authorized Investigators", "Institutions"]
