     else
       []
 
+  uniq = (things) ->
+    index = {}
+    for thing in things
+      index[thing] = 1
+    return Object.keys(index)
+
   $scope.suggest = (vv) ->
+    term = String(vv).toLowerCase()
     if $scope.parameter.Options
-      return Suggestions.getSuggestions $scope.params, $scope.parameter
+      # Not sure why I had to implement filtering logic here...
+      filter = (s) -> 0 <= String(s).toLowerCase().indexOf term
+      return Suggestions.getSuggestions($scope.params, $scope.parameter)
+                        .then( (sgs) -> sgs.filter filter )
+                        .then( uniq )
     else
       d = $q.defer()
       d.resolve getHistory()


getCurrentValue = (ps, name) -> return p.currentValue for p in ps when p.Name is name


Controllers.controller 'MethodCtrl', ($scope, $q, $log, $http, Suggestions, Defaults, ParamUtils, Storage, parameterHistoryKey, Counter, Markdown) ->
  $scope.params = angular.copy($scope.m.parameters)

  do initParams = ->

  $scope.hasParams = -> Object.keys($scope.params).length > 0
  $scope.parsedData = []
  $scope.tree = expanded: false
  $scope.totalPromises = 0
  $scope.currentParsed = 0
  $scope.percentDone = 0

  startId = TreeParsing.nextId()

  ct = ($scope.headers['content-type'] ? '')
  if APPL_JSON.test ct
    parsed = try
      JSON.parse($scope.res.response)
    catch e
      {}
    $scope.formattedResponse = JSON.stringify(parsed, null, 2) if parsed?

  setTree = (tree) ->
    $scope.parsedData = tree
    $log.debug "Next id = #{ TreeParsing.nextId() }"
  
  $scope.makeBrowseableResponse = ->
    return if $scope.parsedData.length # Already done.
    promises = []
    if $scope.res.response?.length
      if APPL_JSON.test ct
        parsed = try
          JSON.parse($scope.res.response)
        catch e
          {}
        for k, v of parsed
          promises.push TreeParsing.parseObj k, v
      else if TEXT_XML.test(ct) or APPL_XML.test(ct)
        try
          dom = xmlParser.parse $scope.res.response
          promises.push TreeParsing.parseDOMElem(dom.documentElement)
        catch e
          $log.error 'Error parsing xml', e

    if promises.length
      $q.all(promises)
        .then((parsed) -> TreeParsing.expandTree parsed, not $scope.tree.expanded)
        .then setTree, $log.error

  $scope.browseable = APPL_JSON.test(ct) or APPL_XML.test(ct) or TEXT_XML.test(ct)

  $scope.isHTML = TEXT_HTML.test ct

  processingInstructions = /<\?[^?]*\?>/g
  $scope.cleanHTML = $scope.res.response.replace(processingInstructions, '')
