 // MARK: MAIN
 //------------------------------------------------------------------------------
 
-var smc = SMC()
-if smc.open() != kIOReturnSuccess {
+do {
+    try SMCKit.open()
+} catch {
     print("ERROR: Failed to open connection to SMC")
     exit(EX_UNAVAILABLE)
 }
-
 
 let wasSetOptions = CLIOptions.filter { $0.wasSet }
 


func printTemperatureInformation() {
    print("-- TEMPERATURE --")
    let temperatureSensors = smc.getAllValidTemperatureKeys()

    if temperatureSensors.count == 0 {
        print("No known temperature sensors found")
        return
    }


    let sensorWithLongestName = temperatureSensors.maxElement
                            { SMC.Temperature.allValues[$0]!.characters.count <
                              SMC.Temperature.allValues[$1]!.characters.count }

    let longestSensorNameCount =
             SMC.Temperature.allValues[sensorWithLongestName!]!.characters.count


    for key in temperatureSensors {
        var temperatureSensorName = SMC.Temperature.allValues[key]!
        let temperature           = smc.getTemperature(key).tmp


        // Padding to line up temperatures
        let padding = longestSensorNameCount -
                      temperatureSensorName.characters.count
        for var i = 0; i < padding; ++i { temperatureSensorName.extend(" ") }


        let warning = warningLevel(temperature, maxValue: maxTemperatureCelsius)
        let level   = CLIWarnOption.value ? "(\(warning.name))" : ""
        let color   = CLIColorOption.value ? warning.color : ANSIColor.Off

        let smcKey  = CLIDisplayKeysOption.value ? "(\(key.rawValue))" : ""

        print("\(temperatureSensorName)   \(smcKey)  ", appendNewline: false)
        print("\(color.rawValue)\(temperature)°C \(level)" +
                                "\(ANSIColor.Off.rawValue)")
    }
}

func printFanInformation() {
    print("-- FAN --")
    let fanCount = smc.getNumFans().numFans

    if fanCount == 0 { print("** Fanless **") }
    else {
        for var i: UInt = 0; i < fanCount; ++i {
            let name    = smc.getFanName(i).name
            let current = smc.getFanRPM(i).rpm
            let min     = smc.getFanMinRPM(i).rpm
            let max     = smc.getFanMaxRPM(i).rpm

            let warning = warningLevel(Double(current), maxValue: Double(max))
            let level   = CLIWarnOption.value ? "(\(warning.name))" : ""
            let color   = CLIColorOption.value ? warning.color : ANSIColor.Off

            print("[id \(i)] \(name)")
            print("\tCurrent:  \(color.rawValue)\(current) RPM \(level)" +
                                                    "\(ANSIColor.Off.rawValue)")
            print("\tMin:      \(min) RPM")
            print("\tMax:      \(max) RPM")
        }
    }
}

func printPowerInformation() {
    print("-- POWER --")
    print("AC Present:       \(colorBoolOutput(smc.isACPresent().flag))")
    print("Battery Powered:  \(colorBoolOutput(smc.isBatteryPowered().flag))")
    print("Charging:         \(colorBoolOutput(smc.isCharging().flag))")
    print("Battery Ok:       \(colorBoolOutput(smc.isBatteryOk().flag))")
    print("Max Batteries:    \(smc.maxNumberBatteries().count)")
}

func printMiscInformation() {
    print("-- MISC --")

    let ODDStatus = smc.isOpticalDiskDriveFull().flag
    print("Disc in ODD:      \(colorBoolOutput(ODDStatus))")
}


}

//------------------------------------------------------------------------------
// MARK: CLI
//------------------------------------------------------------------------------

let CLIColorOption       = BoolOption(shortFlag: "c", longFlag: "color",
