Pass through Signer file for cleanup
diff --git a/.gitignore b/.gitignore
index 1ccffe9..89b9e01 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,7 @@
 *.i*86
 *.x86_64
 *.hex
+a.bat
 
 # Debug files
 *.dSYM/
@@ -63,4 +64,9 @@
 *.tcl
 
 # Coverity
-cov-int
\ No newline at end of file
+cov-int
+
+# Doxygen
+html
+latex
+doxygen.bat
diff --git a/src/Sign.c b/src/Sign.c
index 74f4976..3065bb0 100644
--- a/src/Sign.c
+++ b/src/Sign.c
@@ -173,7 +173,7 @@
 
 	cbor2 = cn_cbor_int_create(algId, CBOR_CONTEXT_PARAM_COMMA &cbor_error);
 	CHECK_CONDITION_CBOR(cbor2 != NULL, cbor_error);
-	if (!COSE_Signer_map_put(hSigner, COSE_Header_Algorithm, cbor2, COSE_PROTECT_ONLY, perr)) goto errorReturn;
+	if (!COSE_Signer_map_put_int(hSigner, COSE_Header_Algorithm, cbor2, COSE_PROTECT_ONLY, perr)) goto errorReturn;
 	cbor2 = NULL;
 
 	cbor = cn_cbor_mapget_int(pkey, COSE_Key_ID);
@@ -181,7 +181,7 @@
 		CHECK_CONDITION(cbor->type == CN_CBOR_BYTES, COSE_ERR_INVALID_PARAMETER);
 		cbor2 = cn_cbor_data_create(cbor->v.bytes, (int) cbor->length, CBOR_CONTEXT_PARAM_COMMA &cbor_error);
 		CHECK_CONDITION_CBOR(cbor2 != NULL, cbor_error);
-		if (!COSE_Signer_map_put(hSigner, COSE_Header_KID, cbor2, COSE_UNPROTECT_ONLY, perr)) goto errorReturn;
+		if (!COSE_Signer_map_put_int(hSigner, COSE_Header_KID, cbor2, COSE_UNPROTECT_ONLY, perr)) goto errorReturn;
 		cbor2 = NULL;
 	}
 
diff --git a/src/SignerInfo.c b/src/SignerInfo.c
index f2927ef..1eb1676 100644
--- a/src/SignerInfo.c
+++ b/src/SignerInfo.c
@@ -13,36 +13,30 @@
 bool IsValidSignerHandle(HCOSE_SIGNER h)
 {
 	COSE_SignerInfo * p = (COSE_SignerInfo *)h;
-	return _COSE_IsInList(SignerRoot, &p->m_message);
+	return _COSE_IsInList(SignerRoot, (COSE *) p);
 }
 
 
 bool _COSE_SignerInfo_Free(COSE_SignerInfo * pSigner)
 {
-#ifdef USE_CBOR_CONTEXT
-	cn_cbor_context context;
-#endif
-
 	//  Check ref counting
 	if (pSigner->m_message.m_refCount > 1) {
 		pSigner->m_message.m_refCount--;
 		return true;
 	}
 
-#ifdef USE_CBOR_CONTEXT
-	context = pSigner->m_message.m_allocContext;
-#endif
-
 	_COSE_Release(&pSigner->m_message);
 
 	return true;
 }
 
+
 bool COSE_Signer_Free(HCOSE_SIGNER hSigner)
 {
 	COSE_SignerInfo * pSigner = (COSE_SignerInfo *)hSigner;
+	bool fRet = false;
 
-	if (!IsValidSignerHandle(hSigner))  return false;
+	if (!IsValidSignerHandle(hSigner)) goto errorReturn;
 
 	if (pSigner->m_message.m_refCount > 1) {
 		pSigner->m_message.m_refCount--;
@@ -55,7 +49,9 @@
 
 	COSE_FREE(pSigner, &pSigner->m_message.m_allocContext);
 
-	return true;
+	fRet = true;
+errorReturn:
+	return fRet;
 }
 
 
@@ -90,17 +86,16 @@
 
 	CHECK_CONDITION(cbor->type == CN_CBOR_ARRAY, COSE_ERR_INVALID_PARAMETER);
 
-	if (!_COSE_Init_From_Object(&pSigner->m_message, cbor, CBOR_CONTEXT_PARAM_COMMA perr)) {
-		_COSE_SignerInfo_Free(pSigner);
-		if (pIn == NULL) COSE_FREE(pSigner, context);
-		return NULL;
-	}
+	if (!_COSE_Init_From_Object(&pSigner->m_message, cbor, CBOR_CONTEXT_PARAM_COMMA perr)) goto errorReturn;
 
 	_COSE_InsertInList(&SignerRoot, &pSigner->m_message);
 	return pSigner;
 
 errorReturn:
-	if (pSigner != NULL) COSE_FREE(pSigner, context);
+	if (pSigner != NULL) {
+		_COSE_SignerInfo_Free(pSigner);
+		if (pIn == NULL) COSE_FREE(pSigner, context);
+	}
 	return NULL;
 }
 
@@ -168,39 +163,28 @@
 #ifdef USE_CBOR_CONTEXT
 	cn_cbor_context * context = &pSigner->m_message.m_allocContext;
 #endif
-	cn_cbor * pcborBody2 = NULL;
-	cn_cbor * pcborProtected2 = NULL;
 	cn_cbor * pcborProtectedSign = NULL;
 	cn_cbor * pArray = NULL;
-	cn_cbor * cnX = NULL;
-	cn_cbor * cn = NULL;
+	cn_cbor * cnAlgorithm = NULL;
 	size_t cbToSign;
 	byte * pbToSign = NULL;
 	bool f;
 	int alg;
+	bool fRet = false;
 
 	pArray = cn_cbor_array_create(CBOR_CONTEXT_PARAM_COMMA NULL);
-	if (pArray == NULL) {
-		if (perr != NULL) perr->err = COSE_ERR_OUT_OF_MEMORY;
-	errorReturn:
-		if (cn != NULL) CN_CBOR_FREE(cn, context);
-		if (pcborBody2 != NULL) CN_CBOR_FREE(pcborBody2, context);
-		if (pcborProtected2 != NULL) CN_CBOR_FREE(pcborProtected2, context);
-		if (pArray != NULL) COSE_FREE(pArray, context);
-		if (pbToSign != NULL) COSE_FREE(pbToSign, context);
-		return false;
-	}
+	CHECK_CONDITION(pArray != NULL, COSE_ERR_OUT_OF_MEMORY);
 
-	cnX = _COSE_map_get_int(&pSigner->m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
-	if (cnX == NULL) goto errorReturn;
+	cnAlgorithm = _COSE_map_get_int(&pSigner->m_message, COSE_Header_Algorithm, COSE_BOTH, perr);
+	if (cnAlgorithm == NULL) goto errorReturn;
 
-	if (cnX->type == CN_CBOR_TEXT) {
+	if (cnAlgorithm->type == CN_CBOR_TEXT) {
 		FAIL_CONDITION(COSE_ERR_UNKNOWN_ALGORITHM);
 	}
 	else {
-		CHECK_CONDITION((cnX->type == CN_CBOR_UINT || cnX->type == CN_CBOR_INT), COSE_ERR_INVALID_PARAMETER);
+		CHECK_CONDITION((cnAlgorithm->type == CN_CBOR_UINT || cnAlgorithm->type == CN_CBOR_INT), COSE_ERR_INVALID_PARAMETER);
 
-		alg = (int)cnX->v.uint;
+		alg = (int)cnAlgorithm->v.sint;
 	}
 
 	pcborProtectedSign = _COSE_encode_protected(&pSigner->m_message, perr);
@@ -215,8 +199,6 @@
 
 	case COSE_Algorithm_ECDSA_SHA_384:
 		f = ECDSA_Sign(&pSigner->m_message, INDEX_SIGNATURE, pSigner->m_pkey, 384, pbToSign, cbToSign, perr);
-		cn_cbor * cnProtected = _COSE_arrayget_int(&pSigner->m_message, INDEX_PROTECTED);
-		CHECK_CONDITION((cnProtected != NULL) && (cnProtected->type == CN_CBOR_BYTES), COSE_ERR_INVALID_PARAMETER);
 		break;
 
 	case COSE_Algorithm_ECDSA_SHA_512:
@@ -227,10 +209,12 @@
 		FAIL_CONDITION(COSE_ERR_INVALID_PARAMETER);
 	}
 
-	COSE_FREE(pbToSign, context);
-	CN_CBOR_FREE(pArray, context);
+	fRet = true;
 
-	return f;
+errorReturn:
+	if (pArray != NULL) COSE_FREE(pArray, context);
+	if (pbToSign != NULL) COSE_FREE(pbToSign, context);
+	return fRet;
 }
 
 bool COSE_Signer_SetKey(HCOSE_SIGNER h, const cn_cbor * pKey, cose_errback * perror)
@@ -248,8 +232,6 @@
 	return true;
 }
 
-byte RgbDontUseSign[8 * 1024];
-
 bool _COSE_Signer_validate(COSE_SignMessage * pSign, COSE_SignerInfo * pSigner, const cn_cbor * pcborBody, const cn_cbor * pcborProtected, cose_errback * perr)
 {
 	byte * pbToBeSigned = NULL;
@@ -274,7 +256,7 @@
 	else {
 		CHECK_CONDITION((cn->type == CN_CBOR_UINT || cn->type == CN_CBOR_INT), COSE_ERR_INVALID_PARAMETER);
 
-		alg = (int)cn->v.uint;
+		alg = (int)cn->v.sint;
 	}
 
 	//  Build protected headers
@@ -315,7 +297,17 @@
 	return fRet;
 }
 
-bool COSE_Signer_map_put(HCOSE_SIGNER h, int key, cn_cbor * value, int flags, cose_errback * perror)
+cn_cbor * COSE_Signer_map_get_int(HCOSE_SIGNER h, int key, int flags, cose_errback * perr)
+{
+	if (!IsValidSignerHandle(h)) {
+		if (perr != NULL) perr->err = COSE_ERR_INVALID_PARAMETER;
+		return NULL;
+	}
+
+	return _COSE_map_get_int((COSE *)h, key, flags, perr);
+}
+
+bool COSE_Signer_map_put_int(HCOSE_SIGNER h, int key, cn_cbor * value, int flags, cose_errback * perror)
 {
 	if (!IsValidSignerHandle(h) || (value == NULL)) {
 		if (perror != NULL) perror->err = COSE_ERR_INVALID_PARAMETER;
diff --git a/src/cose.h b/src/cose.h
index b05cf84..f74d1f4 100644
--- a/src/cose.h
+++ b/src/cose.h
@@ -263,7 +263,8 @@
 HCOSE_SIGNER COSE_Signer_Init(CBOR_CONTEXT_COMMA cose_errback * perror);
 bool COSE_Signer_Free(HCOSE_SIGNER cose);
 bool COSE_Signer_SetKey(HCOSE_SIGNER hSigner, const cn_cbor * pkey, cose_errback * perr);
-bool COSE_Signer_map_put(HCOSE_SIGNER cose, int key, cn_cbor * value, int flags, cose_errback * errp);
+extern cn_cbor * COSE_Signer_map_get_int(HCOSE_SIGNER h, int key, int flags, cose_errback * perr);
+extern bool COSE_Signer_map_put_int(HCOSE_SIGNER cose, int key, cn_cbor * value, int flags, cose_errback * errp);
 
 /*
  *  Sign routines
diff --git a/test/test.c b/test/test.c
index 26f03e4..80094f1 100644
--- a/test/test.c
+++ b/test/test.c
@@ -262,7 +262,7 @@
 			break;
 
 		case Attributes_Signer_protected:
-			f = COSE_Signer_map_put((HCOSE_SIGNER)hHandle, keyNew, pValueNew, which, NULL);
+			f = COSE_Signer_map_put_int((HCOSE_SIGNER)hHandle, keyNew, pValueNew, which, NULL);
 			break;
 
 		case Attributes_Sign0_protected: