         }
     }
 
+    /**
+     Process a data payload from Speech to Text.
+    
+     - parameter data: The data payload from Speech to Text.
+     */
     private func onData(data: NSData) {
         return
     }
 
+    /**
+     Handle a socket error generated by the connection to Speech to Text.
+
+     - parameter error: The error that occurred.
+     */
     private func onSocketError(error: NSError) {
-        socket.disconnect()
-        if let failure = failure {
-            failure(error)
-        }
+        failure?(error)
     }
 
     // MARK: Helper Functions: Parse Generic Response
 
+    /**
+     Handle a state message from Speech to Text.
+
+     - parameter state: The state of the Speech to Text recognition request.
+     */
     private func onState(state: SpeechToTextState) {
         return
     }
 
+    /**
+     Handle transcription results from Speech to Text.
+
+     - parameter wrapper: A `SpeechToTextResultWrapper` that encapsulates the new or updated
+        transcriptions along with state information to update the internal `results` array.
+     */
     private func onResults(wrapper: SpeechToTextResultWrapper) {
         updateResultsArray(wrapper)
         success(results)
     }
 
+    /**
+     Update the `results` array with new or updated transcription results from Speech to Text.
+
+     - parameter wrapper: A `SpeechToTextResultWrapper` that encapsulates the new or updated
+        transcriptions along with state information to update the internal `results` array.
+     */
     private func updateResultsArray(wrapper: SpeechToTextResultWrapper) {
         var localIndex = wrapper.resultIndex
         var wrapperIndex = 0

    private let failure: (NSError -> Void)?
    private let success: [SpeechToTextResult] -> Void

    init?(
        authStrategy: AuthenticationStrategy,
        settings: SpeechToTextSettings,


import Foundation

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

    private let socket: WatsonWebSocket
