             handshakeState = .roundOneRead
             //server will respond with data for roundTwoRead
         } else {
-            handshakeState = .failed
-            self.delegate?.handshakeDidFail(sender: self, error: .FailedToReadRoundOne)
+            fail(withReason: .FailedToReadRoundOne)
         }
     }
 
     private func readRoundTwo(_ data: Data) {
-        NSLog("Handshake: readRoundTwo")
+        log("Handshake: readRoundTwo")
         let result = ecJPakeWrapper.readRoundTwo(data)
 
         if (result == 0) {

    private func getComputedHash() -> Data? {
        let hash = Sha256Wrapper()
        if hash == nil {
            handshakeState = .failed
            delegate?.handshakeDidFail(sender: self, error: .FailedToCreateConfirmation)
            return nil;
        } else {
            var data = Data()

    private func getConfirmKey() -> Data? {
        let hash = Sha256Wrapper()
        if hash == nil {
            fail(withReason: .FailedToCreateConfirmation)
            return nil;
        } else {
            var result = hash!.update(with: derivedSecret!)
