     
     func loadRandomWord() {
         let outputData = TranslationEngineWrapper.queryRandomWord()
-        processData(outputData)
+        processData(outputData, isWord: true)
     }
     
     func loadTranslatedResults() {
-        let outputData = TranslationEngineWrapper.queryAllMatches(inputText)
-        if (outputData.count == 0) {
+        let outputWordData = TranslationEngineWrapper.queryWordMatches(inputText)
+        let outputPhraseData = TranslationEngineWrapper.queryPhraseMatches(inputText)
+        if (outputWordData.count == 0 && outputPhraseData.count == 0) {
             let alert = UIAlertController(title: "No Results Found",
                                           message: "No Matching Word in Dictionary",
                                           preferredStyle: UIAlertControllerStyle.Alert)

    var inputText: String!
    var selectedData: TranslationResult!
    var randomWord: Bool = false
    var translationResults = [TranslationResult]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.contentInset = UIEdgeInsetsMake(-1.0, 0.0, 0.0, 0.0)
        if (randomWord) {
            self.navigationItem.title = "Random Word"
            loadRandomWord()
        } else {
            self.navigationItem.title = "Results"

            }))
            self.presentViewController(alert, animated: true, completion: nil)
        }
        processData(outputWordData, isWord: true)
        processData(outputPhraseData, isWord: false)
    }
    
    func processData(translations: [String], isWord: Bool) {
        for result in translations {
            // Split the string into word and translation
            let resultArr = result.componentsSeparatedByString("-")
            let word = resultArr[0].stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
            let gloss = resultArr[1].stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
            if (isWord) {
                self.translationWordResults.append(TranslationResult(blackfootWord: word, englishGloss: gloss))
            } else {
                self.translationPhraseResults.append(TranslationResult(blackfootWord: word, englishGloss: gloss))
            }
        }
    }
    
    // MARK: TableView functions

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        if (!randomWord) {
            return 2
        } else {
            return 1
        }
    }
    
    override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if (!randomWord) {
            if (section == 0) {
                return 30.0
            } else {
                return 15.0
            }
        }
        return 3.0
    }
    
    override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        if (!randomWord) {
            if (section == 0) {
                return "Words"
            } else if (section == 1) {
                return "Phrases"
            }
        }
        return nil
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if (section == 0) {
            return self.translationWordResults.count
        } else {
            return self.translationPhraseResults.count
        }
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cellIdentifier = "ResultTableViewCell"
        let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! ResultTableViewCell
        if (indexPath.section == 0) {
            let translationResult = self.translationWordResults[indexPath.row]
            cell.blackfootWordLabel.text = translationResult.blackfootWord
            cell.englishGlossLabel.text = translationResult.englishGloss
        } else {
            let translationResult = translationPhraseResults[indexPath.row]
            cell.blackfootWordLabel.text = translationResult.blackfootWord
            cell.englishGlossLabel.text = translationResult.englishGloss
        }
        return cell
    }
    
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
        if segue.identifier == "RowSelectionSegue" {
            let vc: ResultViewController = segue.destinationViewController as! ResultViewController
            vc.englishGloss = self.selectedData.englishGloss
            vc.blackfootWord = self.selectedData.blackfootWord
        }
    }
    
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if (indexPath.section == 0) {
            self.selectedData = self.translationWordResults[indexPath.row]
        } else {
            self.selectedData = self.translationPhraseResults[indexPath.row]
        }
        performSegueWithIdentifier("RowSelectionSegue", sender: self)
    }
}