diff --git a/e2ap/wrapper.c b/e2ap/wrapper.c
index 9e535c8..78c43f7 100644
--- a/e2ap/wrapper.c
+++ b/e2ap/wrapper.c
@@ -5,7 +5,7 @@
 {
     asn_enc_rval_t encode_result;
     encode_result = aper_encode_to_buffer(&asn_DEF_E2AP_PDU, NULL, pdu, buffer, buf_size);
-    if(encode_result.encoded == -1) {
+    if (encode_result.encoded == -1) {
         return -1;
     }
     return encode_result.encoded;
@@ -16,7 +16,7 @@
     asn_dec_rval_t decode_result;
     E2AP_PDU_t *pdu = 0;
     decode_result = aper_decode_complete(NULL, &asn_DEF_E2AP_PDU, (void **)&pdu, buffer, buf_size);
-    if(decode_result.code == RC_OK) {
+    if (decode_result.code == RC_OK) {
         return pdu;
     } else {
         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
@@ -26,275 +26,371 @@
 
 long e2ap_get_ric_subscription_request_sequence_number(void *buffer, size_t buf_size)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
+    if  (pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
     {
         InitiatingMessage_t* initiatingMessage = pdu->choice.initiatingMessage;
-        if ( initiatingMessage->procedureCode == ProcedureCode_id_ricSubscription
+        if (initiatingMessage->procedureCode == ProcedureCode_id_ricSubscription
             && initiatingMessage->value.present == InitiatingMessage__value_PR_RICsubscriptionRequest)
         {
             RICsubscriptionRequest_t *ric_subscription_request = &(initiatingMessage->value.choice.RICsubscriptionRequest);
-            for (int i = 0; i < ric_subscription_request->protocolIEs.list.count; ++i )
+            for (int i = 0; i < ric_subscription_request->protocolIEs.list.count; ++i)
             {
-                if ( ric_subscription_request->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (ric_subscription_request->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
-                    return ric_subscription_request->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    long sequence_number = ric_subscription_request->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return sequence_number;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 ssize_t  e2ap_set_ric_subscription_request_sequence_number(void *buffer, size_t buf_size, long sequence_number)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
     {
         InitiatingMessage_t* initiatingMessage = pdu->choice.initiatingMessage;
-        if ( initiatingMessage->procedureCode == ProcedureCode_id_ricSubscription
+        if (initiatingMessage->procedureCode == ProcedureCode_id_ricSubscription
             && initiatingMessage->value.present == InitiatingMessage__value_PR_RICsubscriptionRequest)
         {
             RICsubscriptionRequest_t *ricSubscriptionRequest = &initiatingMessage->value.choice.RICsubscriptionRequest;
-            for (int i = 0; i < ricSubscriptionRequest->protocolIEs.list.count; ++i )
+            for (int i = 0; i < ricSubscriptionRequest->protocolIEs.list.count; ++i)
             {
-                if ( ricSubscriptionRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (ricSubscriptionRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
                     ricSubscriptionRequest->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
-                    return encode_E2AP_PDU(pdu, buffer, buf_size);
+                    size_t encode_size = encode_E2AP_PDU(pdu, buffer, buf_size);
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return encode_size;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            return -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 /* RICsubscriptionResponse */
 long e2ap_get_ric_subscription_response_sequence_number(void *buffer, size_t buf_size)
 {
-    E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome )
+    int errorCode = -1;
+     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome)
     {
         SuccessfulOutcome_t* successfulOutcome = pdu->choice.successfulOutcome;
-        if ( successfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
+        if (successfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
             && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICsubscriptionResponse)
         {
             RICsubscriptionResponse_t *ricSubscriptionResponse = &successfulOutcome->value.choice.RICsubscriptionResponse;
-            for (int i = 0; i < ricSubscriptionResponse->protocolIEs.list.count; ++i )
+            for (int i = 0; i < ricSubscriptionResponse->protocolIEs.list.count; ++i)
             {
-                if ( ricSubscriptionResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (ricSubscriptionResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
-                    return ricSubscriptionResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    long sequence_number = ricSubscriptionResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return sequence_number;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 ssize_t  e2ap_set_ric_subscription_response_sequence_number(void *buffer, size_t buf_size, long sequence_number)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome)
     {
         SuccessfulOutcome_t* successfulOutcome = pdu->choice.successfulOutcome;
-        if ( successfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
+        if (successfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
             && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICsubscriptionResponse)
         {
             RICsubscriptionResponse_t *ricSubscriptionResponse = &successfulOutcome->value.choice.RICsubscriptionResponse;
-            for (int i = 0; i < ricSubscriptionResponse->protocolIEs.list.count; ++i )
+            for (int i = 0; i < ricSubscriptionResponse->protocolIEs.list.count; ++i)
             {
-                if ( ricSubscriptionResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (ricSubscriptionResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
                     ricSubscriptionResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
-                    return encode_E2AP_PDU(pdu, buffer, buf_size);
+                    size_t encode_size = encode_E2AP_PDU(pdu, buffer, buf_size);
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return encode_size;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 /* RICsubscriptionDeleteRequest */
 long e2ap_get_ric_subscription_delete_request_sequence_number(void *buffer, size_t buf_size)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
     {
         InitiatingMessage_t* initiatingMessage = pdu->choice.initiatingMessage;
-        if ( initiatingMessage->procedureCode == ProcedureCode_id_ricSubscriptionDelete
-            && initiatingMessage->value.present == InitiatingMessage__value_PR_RICsubscriptionDeleteRequest )
+        if (initiatingMessage->procedureCode == ProcedureCode_id_ricSubscriptionDelete
+            && initiatingMessage->value.present == InitiatingMessage__value_PR_RICsubscriptionDeleteRequest)
         {
             RICsubscriptionDeleteRequest_t *subscriptionDeleteRequest = &initiatingMessage->value.choice.RICsubscriptionDeleteRequest;
-            for (int i = 0; i < subscriptionDeleteRequest->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionDeleteRequest->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionDeleteRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionDeleteRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
-                    return subscriptionDeleteRequest->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    long sequence_number = subscriptionDeleteRequest->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return sequence_number;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 ssize_t  e2ap_set_ric_subscription_delete_request_sequence_number(void *buffer, size_t buf_size, long sequence_number)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_initiatingMessage)
     {
         InitiatingMessage_t* initiatingMessage = pdu->choice.initiatingMessage;
-        if ( initiatingMessage->procedureCode == ProcedureCode_id_ricSubscriptionDelete
-            && initiatingMessage->value.present == InitiatingMessage__value_PR_RICsubscriptionDeleteRequest )
+        if (initiatingMessage->procedureCode == ProcedureCode_id_ricSubscriptionDelete
+            && initiatingMessage->value.present == InitiatingMessage__value_PR_RICsubscriptionDeleteRequest)
         {
             RICsubscriptionDeleteRequest_t* subscriptionDeleteRequest = &initiatingMessage->value.choice.RICsubscriptionDeleteRequest;
-            for (int i = 0; i < subscriptionDeleteRequest->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionDeleteRequest->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionDeleteRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionDeleteRequest->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
                     subscriptionDeleteRequest->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
-                    return encode_E2AP_PDU(pdu, buffer, buf_size);
+                    size_t encode_size = encode_E2AP_PDU(pdu, buffer, buf_size);
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return encode_size;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 /* RICsubscriptionDeleteResponse */
 long e2ap_get_ric_subscription_delete_response_sequence_number(void *buffer, size_t buf_size)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome)
     {
         SuccessfulOutcome_t* successfulOutcome = pdu->choice.successfulOutcome;
-        if ( successfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
-            && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse )
+        if (successfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
+            && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse)
         {
             RICsubscriptionDeleteResponse_t* subscriptionDeleteResponse = &successfulOutcome->value.choice.RICsubscriptionDeleteResponse;
-            for (int i = 0; i < subscriptionDeleteResponse->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionDeleteResponse->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionDeleteResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionDeleteResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
-                    return subscriptionDeleteResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    long sequence_number = subscriptionDeleteResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return sequence_number;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 ssize_t  e2ap_set_ric_subscription_delete_response_sequence_number(void *buffer, size_t buf_size, long sequence_number)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_successfulOutcome)
     {
         SuccessfulOutcome_t* successfulOutcome = pdu->choice.successfulOutcome;
-        if ( successfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
-            && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse )
+        if (successfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
+            && successfulOutcome->value.present == SuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse)
         {
             RICsubscriptionDeleteResponse_t* subscriptionDeleteResponse = &successfulOutcome->value.choice.RICsubscriptionDeleteResponse;
-            for (int i = 0; i < subscriptionDeleteResponse->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionDeleteResponse->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionDeleteResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionDeleteResponse->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
                     subscriptionDeleteResponse->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
-                    return encode_E2AP_PDU(pdu, buffer, buf_size);
+                    size_t encode_size = encode_E2AP_PDU(pdu, buffer, buf_size);
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return encode_size;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 // This function is not used currently. Can be deleted if not needed
 ssize_t  e2ap_set_ric_subscription_failure_sequence_number(void *buffer, size_t buf_size, long sequence_number)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome)
     {
         UnsuccessfulOutcome_t* unsuccessfulOutcome = pdu->choice.unsuccessfulOutcome;
-        if ( unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
-            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionFailure )
+        if (unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
+            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionFailure)
         {
             RICsubscriptionFailure_t* subscriptionFailure = &unsuccessfulOutcome->value.choice.RICsubscriptionFailure;
-            for (int i = 0; i < subscriptionFailure->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionFailure->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
                     subscriptionFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
-                    return encode_E2AP_PDU(pdu, buffer, buf_size);
+                    size_t encode_size = encode_E2AP_PDU(pdu, buffer, buf_size);
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return encode_size;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 long e2ap_get_ric_subscription_failure_sequence_number(void *buffer, size_t buf_size)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome)
     {
         UnsuccessfulOutcome_t* unsuccessfulOutcome = pdu->choice.unsuccessfulOutcome;
-        if ( unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
-            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionFailure )
+        if (unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscription
+            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionFailure)
         {
             RICsubscriptionFailure_t* subscriptionFailure = &unsuccessfulOutcome->value.choice.RICsubscriptionFailure;;
-            for (int i = 0; i < subscriptionFailure->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionFailure->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
-                    return subscriptionFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    long sequence_number = subscriptionFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return sequence_number;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 // This function is not used currently. Can be deleted if not needed
 ssize_t  e2ap_set_ric_subscription_delete_failure_sequence_number(void *buffer, size_t buf_size, long sequence_number)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome)
     {
         UnsuccessfulOutcome_t* unsuccessfulOutcome = pdu->choice.unsuccessfulOutcome;
-        if ( unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
-            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure )
+        if (unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
+            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure)
         {
             RICsubscriptionDeleteFailure_t* subscriptionDeleteFailure = &unsuccessfulOutcome->value.choice.RICsubscriptionDeleteFailure;
-            for (int i = 0; i < subscriptionDeleteFailure->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionDeleteFailure->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionDeleteFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionDeleteFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
                     subscriptionDeleteFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber = sequence_number;
-                    return encode_E2AP_PDU(pdu, buffer, buf_size);
+                    size_t encode_size = encode_E2AP_PDU(pdu, buffer, buf_size);
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return encode_size;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
 
 long e2ap_get_ric_subscription_delete_failure_sequence_number(void *buffer, size_t buf_size)
 {
+    int errorCode = -1;
     E2AP_PDU_t *pdu = decode_E2AP_PDU(buffer, buf_size);
-    if ( pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome )
+    if (pdu != NULL && pdu->present == E2AP_PDU_PR_unsuccessfulOutcome)
     {
         UnsuccessfulOutcome_t* unsuccessfulOutcome = pdu->choice.unsuccessfulOutcome;
-        if ( unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
-            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure )
+        if (unsuccessfulOutcome->procedureCode == ProcedureCode_id_ricSubscriptionDelete
+            && unsuccessfulOutcome->value.present == UnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure)
         {
             RICsubscriptionDeleteFailure_t* subscriptionDeleteFailure = &unsuccessfulOutcome->value.choice.RICsubscriptionDeleteFailure;;
-            for (int i = 0; i < subscriptionDeleteFailure->protocolIEs.list.count; ++i )
+            for (int i = 0; i < subscriptionDeleteFailure->protocolIEs.list.count; ++i)
             {
-                if ( subscriptionDeleteFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID )
+                if (subscriptionDeleteFailure->protocolIEs.list.array[i]->id == ProtocolIE_ID_id_RICrequestID)
                 {
-                    return subscriptionDeleteFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    long sequence_number = subscriptionDeleteFailure->protocolIEs.list.array[i]->value.choice.RICrequestID.ricRequestSequenceNumber;
+                    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+                    return sequence_number;
                 }
+                else
+                    errorCode = -3;
             }
         }
+        else
+            errorCode = -2;
     }
-    return -1;
+    ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu);
+    return errorCode;
 }
diff --git a/pkg/control/client.go b/pkg/control/client.go
index d377d8e..adbe48f 100644
--- a/pkg/control/client.go
+++ b/pkg/control/client.go
@@ -61,7 +61,7 @@
 			return nil
 		}
 	default:
-		xapp.Logger.Debug("Unknown subRouteAction.Command: %v, subID: %v", subRouteAction.Command, subRouteAction.Address, subRouteAction.Port, subID)
+		xapp.Logger.Debug("Unknown subRouteAction.Command: %v, Address %s, Port %v, subID: %v", subRouteAction.Command, subRouteAction.Address, subRouteAction.Port, subID)
 		return nil
 	}
 }
diff --git a/pkg/control/control.go b/pkg/control/control.go
index af629a1..7e2d673 100644
--- a/pkg/control/control.go
+++ b/pkg/control/control.go
@@ -172,7 +172,7 @@
 		return 
 	}
 
-	_, err = c.e2ap.SetSubscriptionRequestSequenceNumber(params.Payload, newSubId)
+	err = c.e2ap.SetSubscriptionRequestSequenceNumber(params.Payload, newSubId)
 	if err != nil {
 		err = errors.New("Unable to set Subscription Sequence Number in Payload due to: " + err.Error())
 		return
@@ -214,7 +214,7 @@
 }
 
 func (c *Control) handleSubscriptionResponse(params *xapp.RMRParams) (err error) {
-	xapp.Logger.Info("Subscription Response Received from Src: %s, Mtype: %v, SubId: %v, Meid: %v",params.Src, params.Mtype, params.SubId, params.Xid, params.Meid)
+	xapp.Logger.Info("Subscription Response Received from Src: %s, Mtype: %v, SubId: %v, Meid: %v",params.Src, params.Mtype, params.SubId, params.Meid)
 	xapp.Rmr.Free(params.Mbuf)
 	params.Mbuf = nil
 
@@ -297,7 +297,7 @@
 	time.Sleep(3 * time.Second)
 
 	xapp.Logger.Info("Starting routing manager update")
-	subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
+	subRouteAction := SubRouteInfo{CREATE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
 	c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
 
 	xapp.Logger.Info("Deleting trancaction record")
diff --git a/pkg/control/e2ap.go b/pkg/control/e2ap.go
index f9580d9..8f9f7c9 100644
--- a/pkg/control/e2ap.go
+++ b/pkg/control/e2ap.go
@@ -27,139 +27,144 @@
 import "C"
 
 import (
-	"errors"
 	"unsafe"
+	"fmt"
 )
 
 type E2ap struct {
 }
 
+/* RICsubscriptionRequest */
+
+// Used by e2t test stub
 func (c *E2ap) GetSubscriptionRequestSequenceNumber(payload []byte) (subId uint16, err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	cret := C.e2ap_get_ric_subscription_request_sequence_number(cptr, C.size_t(len(payload)))
 	if cret < 0 {
-		return 0, errors.New("e2ap wrapper is unable to get Subscirption Request Sequence Number due to wrong or invalid payload")
+		return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Request Sequence Number due to wrong or invalid payload. ErrorCode: %v",cret)
 	}
 	subId = uint16(cret)
 	return
 }
 
-func (c *E2ap) SetSubscriptionRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
+// Used by submgr, rco test stub
+func (c *E2ap) SetSubscriptionRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	size := C.e2ap_set_ric_subscription_request_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
 	if size < 0 {
-		return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Request Sequence Number due to wrong or invalid payload")
+		return fmt.Errorf("e2ap wrapper is unable to set Subscription Request Sequence Number due to wrong or invalid payload. ErrorCode: %v",size)
 	}
-	newPayload = C.GoBytes(cptr, C.int(size))
 	return
 }
 
+// Used by submgr, rco test stub
 func (c *E2ap) GetSubscriptionResponseSequenceNumber(payload []byte) (subId uint16, err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	cret := C.e2ap_get_ric_subscription_response_sequence_number(cptr, C.size_t(len(payload)))
 	if cret < 0 {
-		return 0, errors.New("e2ap wrapper is unable to get Subscirption Response Sequence Number due to wrong or invalid payload")
+		return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Response Sequence Number due to wrong or invalid payload. ErrorCode: %v",cret)
 	}
 	subId = uint16(cret)
 	return
 }
 
-func (c *E2ap) SetSubscriptionResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
+// Used by e2t test stub
+func (c *E2ap) SetSubscriptionResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (err error)  {
 	cptr := unsafe.Pointer(&payload[0])
 	size := C.e2ap_set_ric_subscription_response_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
 	if size < 0 {
-		return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Response Sequence Number due to wrong or invalid payload")
+		return fmt.Errorf("e2ap wrapper is unable to set Subscription Response Sequence Number due to wrong or invalid payload. ErrorCode: %v",size)
 	}
-	newPayload = C.GoBytes(cptr, C.int(size))
 	return
 }
 
 /* RICsubscriptionDeleteRequest */
 
+// Used by submgr, e2t test stub
 func (c *E2ap) GetSubscriptionDeleteRequestSequenceNumber(payload []byte) (subId uint16, err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	cret := C.e2ap_get_ric_subscription_delete_request_sequence_number(cptr, C.size_t(len(payload)))
 	if cret < 0 {
-		return 0, errors.New("e2ap wrapper is unable to get Subscirption Delete Request Sequence Number due to wrong or invalid payload")
+		return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Delete Request Sequence Number due to wrong or invalid payload. ErrorCode: %v",cret)
 	}
 	subId = uint16(cret)
 	return
 }
 
-func (c *E2ap) SetSubscriptionDeleteRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
+// Used by rco test stub
+func (c *E2ap) SetSubscriptionDeleteRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (err error)  {
 	cptr := unsafe.Pointer(&payload[0])
 	size := C.e2ap_set_ric_subscription_delete_request_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
 	if size < 0 {
-		return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Delete Request Sequence Number due to wrong or invalid payload")
+		return fmt.Errorf("e2ap wrapper is unable to set Subscription Delete Request Sequence Number due to wrong or invalid payload. ErrorCode: %v",size)
 	}
-	newPayload = C.GoBytes(cptr, C.int(size))
 	return
 }
 
 /* RICsubscriptionDeleteResponse */
 
+// Used by submgr, rco test stub
 func (c *E2ap) GetSubscriptionDeleteResponseSequenceNumber(payload []byte) (subId uint16, err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	cret := C.e2ap_get_ric_subscription_delete_response_sequence_number(cptr, C.size_t(len(payload)))
 	if cret < 0 {
-		return 0, errors.New("e2ap wrapper is unable to get Subscirption Delete Response Sequence Number due to wrong or invalid payload")
+		return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Delete Response Sequence Number due to wrong or invalid payload. ErrorCode: %v",cret)
 	}
 	subId = uint16(cret)
 	return
 }
 
-func (c *E2ap) SetSubscriptionDeleteResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
+// Used by e2t test stub
+func (c *E2ap) SetSubscriptionDeleteResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (err error)  {
 	cptr := unsafe.Pointer(&payload[0])
 	size := C.e2ap_set_ric_subscription_delete_response_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
 	if size < 0 {
-		return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Delete Response Sequence Number due to wrong or invalid payload")
+		return fmt.Errorf("e2ap wrapper is unable to set Subscription Delete Response Sequence Number due to wrong or invalid payload. ErrorCode: %v",size)
 	}
-	newPayload = C.GoBytes(cptr, C.int(size))
 	return
 }
 
 /* RICsubscriptionRequestFailure */
 
+// Used by submgr
 func (c *E2ap) GetSubscriptionFailureSequenceNumber(payload []byte) (subId uint16, err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	cret := C.e2ap_get_ric_subscription_failure_sequence_number(cptr, C.size_t(len(payload)))
 	if cret < 0 {
-		return 0, errors.New("e2ap wrapper is unable to get Subscirption Failure Sequence Number due to wrong or invalid payload")
+		return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Failure Sequence Number due to wrong or invalid payload. ErrorCode: %v",cret)
 	}
 	subId = uint16(cret)
 	return
 }
 
-// This function is not used currently. Can be deleted if not needed
-func (c *E2ap) SetSubscriptionFailureSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
+// Used by submgr
+func (c *E2ap) SetSubscriptionFailureSequenceNumber(payload []byte, newSubscriptionid uint16) (err error)  {
 	cptr := unsafe.Pointer(&payload[0])
 	size := C.e2ap_set_ric_subscription_failure_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
 	if size < 0 {
-		return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Failure Sequence Number due to wrong or invalid payload")
+		return fmt.Errorf("e2ap wrapper is unable to set Subscription Failure Sequence Number due to wrong or invalid payload. ErrorCode: %v",size)
 	}
-	newPayload = C.GoBytes(cptr, C.int(size))
 	return
 }
 
 /* RICsubscriptionDeleteFailure */
 
+// Used by submgr
 func (c *E2ap) GetSubscriptionDeleteFailureSequenceNumber(payload []byte) (subId uint16, err error) {
 	cptr := unsafe.Pointer(&payload[0])
 	cret := C.e2ap_get_ric_subscription_delete_failure_sequence_number(cptr, C.size_t(len(payload)))
 	if cret < 0 {
-		return 0, errors.New("e2ap wrapper is unable to get Subscirption Delete Failure Sequence Number due to wrong or invalid payload")
+		return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Delete Failure Sequence Number due to wrong or invalid payload. ErrorCode: %v",cret)
 	}
 	subId = uint16(cret)
 	return
 }
-
-// This function is not used currently. Can be deleted if not needed
-func (c *E2ap) SetSubscriptionDeleteFailureSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
+// Used by submgr
+func (c *E2ap) SetSubscriptionDeleteFailureSequenceNumber(payload []byte, newSubscriptionid uint16) (err error)  {
 	cptr := unsafe.Pointer(&payload[0])
 	size := C.e2ap_set_ric_subscription_delete_failure_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
 	if size < 0 {
-		return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Delete Failure Sequence Number due to wrong or invalid payload")
+		return fmt.Errorf("e2ap wrapper is unable to set Subscription Delete Failure Sequence Number due to wrong or invalid payload. ErrorCode: %v",size)
 	}
-	newPayload = C.GoBytes(cptr, C.int(size))
 	return
 }
