   exit(EXIT_FAILURE)
 }
 
-func storePassword(password: String?) -> Result<String, QCError> {
-  guard let password = password else {
-    return .Failure(.PasswordNotFound)
-  }
+func storePassword(password: String) -> Result<String, QCError> {
   defaults.password = password
   return .Success(password)
 }
 
+func storeNetwork(network: String) -> Result<String, QCError> {
+  defaults.network = network
+  return .Success(network)
+}
+
 func updatePassword(password: String?) -> Result<String, QCError> {
+  return updateValue(password,
+    validator: validatePassword,
+    store: storePassword,
+    confirmation: {_ in .Success("Password updated! 🍻") }
+  )
+}
+
+func updateNetwork(network: String?) -> Result<String, QCError> {
+  return updateValue(network,
+    validator: validateNetwork,
+    store: storeNetwork,
+    confirmation: {_ in .Success("Network updated! 🍻")})
+}
+
+func updateValue<T>(value: T?, validator validate: T? -> Result<T, QCError>, store storeValue: T -> Result<T, QCError>, confirmation sendConfirmation: T -> Result<String, QCError>) -> Result<String, QCError> {
   return
-    validatePassword(password)
-    >>- storePassword
-    >>- {_ in .Success("Password updated! 🍻") }
+    validate(value)
+    >>- storeValue
+    >>- sendConfirmation
+}
+
+func validateValue<T>(value: T?, error: QCError) -> Result<T, QCError> {
+  switch value {
+  case let .Some(value): return .Success(value)
+  case .None: return .Failure(error)
+  }
 }
 
 func validatePassword(password: String?) -> Result<String, QCError> {
-  switch password {
-  case .Some(let password): return .Success(password)
-  case .None: return .Failure(.PasswordNotFound)
-  }
+  return validateValue(password, error: .PasswordNotSet)
 }
 
 func validateNetwork(network: String?) -> Result<String, QCError> {
-  return .Success(network ?? "Intel Network")
+  return validateValue(network, error: .NetworkNotSet)
 }
 
 func createScript(password: String, network: String) -> Result<NSAppleScript, QCError> {
-  let source = String(format: format, password)
-  switch NSAppleScript(source: source) {
-  case let .Some(script): return .Success(script)
-  case .None: return .Failure(.CouldNotCreateScript(source))
-  }
+  let source = String(format: format, network, password)
+  let script = NSAppleScript(source: source)
+  return validateValue(script, error: .CouldNotCreateScript(source))
 }
 
 func executeScript(script: NSAppleScript) ->  Result<NSAppleEventDescriptor, QCError> {

  }
}

func connect(password: String?, network: String?) -> Result<NSAppleEventDescriptor, QCError> {
  return
    validatePassword(password) &&& validateNetwork(network)
    >>- createScript
    >>- executeScript
}

import Foundation

enum QCError: ErrorType {
  case PasswordNotSet
  case NetworkNotSet
  case CouldNotCreateScript(String)
  case AppleScriptError(NSDictionary)
}
