     
     override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
         
+        // Pass the currency we are changing (input or output) and
+        // the current currency code to the Change Currency View Controller.
+        
         if segue.identifier == "ChangeInputCurrency" {
             let changeCurrencyViewController = (segue.destinationViewController as! UINavigationController).topViewController as! ChangeCurrencyViewController
             changeCurrencyViewController.targetCurrency = "input"
-            changeCurrencyViewController.selectedCurrency = inputCurrencyCodeButton.titleLabel!.text
+            changeCurrencyViewController.selectedCurrency = converter.inputCurrency.code
             changeCurrencyViewController.delegate = self
         }
         
         if segue.identifier == "ChangeOutputCurrency" {
             let changeCurrencyViewController = (segue.destinationViewController as! UINavigationController).topViewController as! ChangeCurrencyViewController
             changeCurrencyViewController.targetCurrency = "output"
-            changeCurrencyViewController.selectedCurrency = outputCurrencyCodeButton.titleLabel!.text
+            changeCurrencyViewController.selectedCurrency = converter.outputCurrency.code
             changeCurrencyViewController.delegate = self
         }
         

    }
    
    func updateInterface() {
        inputCurrencyLabel.text = converter.inputValue()
        outputCurrencyLabel.text = converter.outputValue()
        inputCurrencyCodeButton.setTitle(converter.inputCurrency.code, forState: .Normal)


extension MainViewController: ChangeCurrencyViewControllerDelegate {
    
    // After selecting a new currency from the Change Currency View Controller,
    // set it as the new currency and update the interface.
    // At this point, also save it to the user preferences file.
    
    func didChangeCurrency(currencyCode: String, targetCurrency: String) {
        if targetCurrency == "input" {
            converter.setInputCurrency(currencyCode)
            prefs.setObject(currencyCode, forKey: "input")
            print("Input currency updated to: \(currencyCode)")
        }
        if targetCurrency == "output" {
            converter.setOutputCurrency(currencyCode)
            prefs.setObject(currencyCode, forKey: "output")
            print("Output currency updated to: \(currencyCode)")
        }
