       var toUnit: Dictionary<String,Dimension> = [:]
       if let defaultUnits = defaults.dictionary(forKey: measurement.header) {
         let fromUnitName = defaultUnits["fromUnit"] as! String
-        fromUnit = getUnit(unitName: fromUnitName, measurement: measurement)
         let toUnitName = defaultUnits["toUnit"] as! String
-        toUnit = getUnit(unitName: toUnitName, measurement: measurement)
+        if let fUnit = getUnit(unitName: fromUnitName, measurement: measurement), let tUnit = getUnit(unitName: toUnitName, measurement: measurement) {
+          fromUnit = fUnit
+          toUnit = tUnit
+        } else {
+          fromUnit = measurement.SIValues[0]
+          toUnit = measurement.imperialValues[0]
+          self.defaults.set(["fromUnit": fromUnit.keys.first, "toUnit": toUnit.keys.first], forKey: measurement.header)
+        }
       } else {
         fromUnit = measurement.SIValues[0]
         toUnit = measurement.imperialValues[0]

    }
  }

  func getUnit(unitName: String, measurement: MyMeasurement) -> Dictionary<String, Dimension> {
    let foundFromSIValues = measurement.SIValues.filter({(unit: Dictionary<String,Dimension>) -> Bool in
      if let key = unit.keys.first {
        return key == unitName
      } else {
        return false
      }
    })
    if (foundFromSIValues.count > 0) {
      return foundFromSIValues.first!
    } else {
      let foundFromImperialValues = measurement.imperialValues.filter({(unit: Dictionary<String,Dimension>) -> Bool in
        if let key = unit.keys.first {
          return key == unitName
        } else {
          return false
        }
      })
      return foundFromImperialValues.first!
    }
  }


  public func toUnitSelected(toUnit: Dictionary<String,Dimension>) {
    if let measurement = self.dataObject {
      let defaultUnits = defaults.dictionary(forKey: measurement.header)
      self.defaults.set(["fromUnit": defaultUnits?["fromUnit"] as! String, "toUnit": toUnit.keys.first!], forKey: self.dataLabel!.text!)
      let toUnitName = toUnit.keys.first
      self.toButton.setTitle(toUnitName, for: .normal)
      self.selectedToUnit = toUnit[toUnitName!]
