 
     // MARK: WatsonWebSocket API Functions
 
+    /**
+     Send data to Speech to Text.
+    
+     - parameter data: The data to send.
+    */
     func writeData(data: NSData) {
         socket.writeData(data)
     }
 
+    /**
+     Send text to Speech to Text.
+
+     - parameter str: The text string to send.
+     */
     func writeString(str: String) {
         socket.writeString(str)
     }
 
+    /**
+     Send a ping to Speech to Text.
+
+     - parameter data: The data to send.
+     */
     func writePing(data: NSData) {
         socket.writePing(data)
     }
 
+    /**
+     Disconnect from Speech to Text.
+
+     - parameter forceTimeout: The time to wait for a graceful disconnect before forcing the
+        connection to close.
+     */
     func disconnect(forceTimeout: NSTimeInterval? = nil) {
         socket.disconnect(forceTimeout)
     }
 
     // MARK: WatsonWebSocket Delegate Functions
 
+    /**
+     Process a text payload from Speech to Text.
+
+     - parameter text: The text payload from Speech to Text.
+     */
     private func onText(text: String) {
         guard let response = SpeechToTextGenericResponse.parseResponse(text) else {
-            if let failure = failure {
-                let description = "Could not serialize a generic text response to an object."
-                let error = createError(SpeechToTextConstants.domain, description: description)
-                failure(error)
-            }
+            let description = "Could not serialize a generic text response to an object."
+            let error = createError(SpeechToTextConstants.domain, description: description)
+            failure?(error)
             return
         }
 

        }
    }

    private func onData(data: NSData) {
        return
    }

    private func onSocketError(error: NSError) {
        socket.disconnect()
        if let failure = failure {
            failure(error)
        }
    }

    // MARK: Helper Functions: Parse Generic Response

    private func onState(state: SpeechToTextState) {
        return
    }

    private func onResults(wrapper: SpeechToTextResultWrapper) {
        updateResultsArray(wrapper)
        success(results)
    }

    private func updateResultsArray(wrapper: SpeechToTextResultWrapper) {
        var localIndex = wrapper.resultIndex
        var wrapperIndex = 0


import Foundation

/** Abstracts the WebSockets connection to the Watson Speech to Text service. */
class SpeechToTextWebSocket {

    private let socket: WatsonWebSocket
