diff --git a/openair2/LAYER2/PROTO_AGENT/proto_agent.c b/openair2/LAYER2/PROTO_AGENT/proto_agent.c
index a38ffddaf3274cc80959e8651c140d586e72cdea..fd809d5f9a4aabac6137d069de5c753f64ab56af 100644
--- a/openair2/LAYER2/PROTO_AGENT/proto_agent.c
+++ b/openair2/LAYER2/PROTO_AGENT/proto_agent.c
@@ -33,7 +33,6 @@
  * \date 2016
  * \version 0.1
  */
-#include "ENB_APP/flexran_agent_defs.h"
 #include "proto_agent_common.h"
 #include "common/utils/LOG/log.h"
 #include "proto_agent.h"
@@ -57,7 +56,7 @@ pthread_t cu_thread[MAX_DU], du_thread;
 Protocol__FlexsplitMessage *proto_agent_timeout_fsp(void* args);
 
 mod_id_t client_mod[MAX_DU], server_mod;
-proto_agent_instance_t *client_channel[MAX_DU], *server_channel;
+proto_agent_async_channel_t *client_channel[MAX_DU], *server_channel;
 proto_recv_t client_info[MAX_DU];
 
 #define TEST_MOD 0
@@ -161,7 +160,7 @@ void * proto_server_init(void *args)
 int proto_server_start(mod_id_t mod_id, const cudu_params_t* cudu){
   
   int channel_id;
-  char *peer_address;
+  char *peer_address = NULL;
   
   proto_server[mod_id].enb_id = mod_id;
   
@@ -230,7 +229,7 @@ int proto_server_start(mod_id_t mod_id, const cudu_params_t* cudu){
   proto_agent_init_channel_container();
 
   /*Create the async channel info*/
-  proto_agent_instance_t *channel_info = proto_server_async_channel_info(mod_id, in_ip, in_port, link_type, peer_address);
+  proto_agent_async_channel_t *channel_info = proto_server_async_channel_info(mod_id, in_ip, in_port, link_type, peer_address);
   
   server_channel = channel_info;
 
@@ -260,13 +259,9 @@ int proto_server_start(mod_id_t mod_id, const cudu_params_t* cudu){
   proto_agent_register_channel(mod_id, channel, ENB_AGENT_MAX);
 
   // Code for sending the HELLO/ECHO_REQ message once a connection is established
-  Protocol__FlexsplitMessage *msg = NULL;
+  uint8_t *msg = NULL;
   Protocol__FlexsplitMessage *init_msg=NULL;
-  Protocol__FlexsplitMessage *rep_msg=NULL;
-  Protocol__FlexsplitMessage *ser_msg=NULL;
   int msg_flag = 0;
-  int priority;
-  int size;
 
   if (udp == 0)
   {
@@ -277,7 +272,6 @@ int proto_server_start(mod_id_t mod_id, const cudu_params_t* cudu){
     goto error;
   
     int msgsize = 0;
-    int err_code;
     if (init_msg != NULL)
       msg = proto_agent_pack_message(init_msg, &msgsize);
 
@@ -295,7 +289,7 @@ int proto_server_start(mod_id_t mod_id, const cudu_params_t* cudu){
 
   
   du_thread=new_thread(proto_server_receive, &proto_server[mod_id]);
-  LOG_D(PROTO_AGENT, "server ends with thread_id %u\n",du_thread);
+  LOG_D(PROTO_AGENT, "server ends with thread_id %lu\n",du_thread);
   return 0;
 
 error:
@@ -383,7 +377,7 @@ int proto_agent_start(uint8_t enb_id, mod_id_t cu_id, uint8_t type_id, cudu_para
 
   /*Create the async channel info*/
   
-  proto_agent_instance_t *channel_info = proto_agent_async_channel_info(cu_id, in_ip, in_port, link_type, peer_address);
+  proto_agent_async_channel_t *channel_info = proto_agent_async_channel_info(cu_id, in_ip, in_port, link_type, peer_address);
   client_channel[cu_id] = channel_info;
   /*Create a channel using the async channel info*/
   channel_id = proto_agent_create_channel((void *) channel_info, 
@@ -408,14 +402,8 @@ int proto_agent_start(uint8_t enb_id, mod_id_t cu_id, uint8_t type_id, cudu_para
   /*Register the channel for all underlying agents (use ENB_AGENT_MAX)*/
   proto_agent_register_channel(cu_id, channel, ENB_AGENT_MAX);
 
-  void                  *data;
-  int                   size;
-  int                   priority;
-   err_code_t             err_code;
-  Protocol__FlexsplitMessage *msg = NULL;
+  uint8_t *msg = NULL;
   Protocol__FlexsplitMessage *init_msg=NULL;
-  Protocol__FlexsplitMessage *rep_msg=NULL;
-  Protocol__FlexsplitMessage *ser_msg=NULL;
   int msg_flag;
   
   // In the case of UDP comm, start the echo request from the client side; the server thread should be blocked until it reads the SRC port of the 1st packet
@@ -429,7 +417,6 @@ int proto_agent_start(uint8_t enb_id, mod_id_t cu_id, uint8_t type_id, cudu_para
       goto error;
     
     int msgsize = 0;
-    int err_code;
     if (init_msg != NULL)
       msg = proto_agent_pack_message(init_msg, &msgsize);
 
@@ -447,7 +434,7 @@ int proto_agent_start(uint8_t enb_id, mod_id_t cu_id, uint8_t type_id, cudu_para
   return 0;
 
 error:
-  LOG_E(PROTO_AGENT, "there was an error %u\n", err_code);
+  LOG_E(PROTO_AGENT, "there was an error in proto_agent_start()\n");
   return 1;
 
 }
@@ -455,7 +442,7 @@ error:
 void 
 proto_agent_send_hello(void)
 {
-  Protocol__FlexsplitMessage *msg = NULL;
+  uint8_t *msg = NULL;
   Protocol__FlexsplitMessage *init_msg=NULL;
   int msg_flag = 0;
 
@@ -481,17 +468,10 @@ proto_agent_send_rlc_data_req(uint8_t mod_id, uint8_t type_id, const protocol_ct
   
   //LOG_D(PROTO_AGENT, "PROTOPDCP: sending the data req over the async channel\n");
   
-  Protocol__FlexsplitMessage *msg = NULL;
+  uint8_t *msg = NULL;
   Protocol__FlexsplitMessage *init_msg=NULL;
-  Protocol__FlexsplitMessage *rep = NULL;
-  Protocol__FlexsplitMessage *srep = NULL;
 
   int msg_flag = 0;
-  void *data=NULL;
-  int priority;
-  int size;
-  int ret;
-  int err_code;
   
   //printf( "PDCP agent: Calling the PDCP DATA REQ constructor\n");
  
@@ -544,18 +524,11 @@ proto_agent_send_pdcp_data_ind(const protocol_ctxt_t* const ctxt_pP, const srb_f
 {
   //LOG_D(PROTO_AGENT, "PROTOPDCP: Sending Data Indication over the async channel\n");
   
-  Protocol__FlexsplitMessage *msg = NULL;
+  uint8_t *msg = NULL;
   Protocol__FlexsplitMessage *init_msg = NULL;
-  Protocol__FlexsplitMessage *rep = NULL;
-  Protocol__FlexsplitMessage *srep = NULL;
 
   
   int msg_flag = 0;
-  void *data=NULL;
-  int priority;
-  int size;
-  int ret;
-  int err_code;
   
   //printf( "PDCP agent: Calling the PDCP_DATA_IND constructor\n");
  
@@ -602,16 +575,16 @@ error:
 
 
 void *
-proto_server_receive(void)
+proto_server_receive(void *args)
 {
-  proto_agent_instance_t         *d = &proto_server[server_mod];
+  proto_agent_instance_t *d = args;
   void                  *data = NULL;
   int                   size;
   int                   priority;
   err_code_t             err_code;
 
   Protocol__FlexsplitMessage *msg;
-  Protocol__FlexsplitMessage *ser_msg;
+  uint8_t *ser_msg;
   
   while (1) {
    
@@ -661,7 +634,6 @@ proto_client_receive(void *args)
   
   proto_recv_t*         recv = args;
   mod_id_t 	      recv_mod = recv->mod_id;
-  uint8_t 	      type = recv->type_id;
 
   LOG_D(PROTO_AGENT, "\n\nrecv mod is %u\n\n",recv_mod);  
   //proto_agent_instance_t         *d = &proto_agent[TEST_MOD];
@@ -671,7 +643,7 @@ proto_client_receive(void *args)
   err_code_t             err_code;
 
   Protocol__FlexsplitMessage *msg;
-  Protocol__FlexsplitMessage *ser_msg;
+  uint8_t *ser_msg;
 
 
   while (1) {
diff --git a/openair2/LAYER2/PROTO_AGENT/proto_agent.h b/openair2/LAYER2/PROTO_AGENT/proto_agent.h
index 65a5d6f5a9e6737fd46cedc412a3ea2dfc89f9df..520a438aa73743eef24cd0f72ed9ad7a8a1c7a84 100644
--- a/openair2/LAYER2/PROTO_AGENT/proto_agent.h
+++ b/openair2/LAYER2/PROTO_AGENT/proto_agent.h
@@ -42,7 +42,7 @@
 
 
 void * proto_server_init(void *args);
-void * proto_server_receive(void);
+void * proto_server_receive(void *args);
 void * proto_client_receive(void *args);
 
 int proto_agent_start(uint8_t enb_id, mod_id_t mod_id, uint8_t type_id, cudu_params_t *cudu);
@@ -59,4 +59,13 @@ typedef struct
   uint8_t type_id;
 }proto_recv_t;
 
+void proto_agent_send_rlc_data_req(uint8_t mod_id, uint8_t type_id,
+    const protocol_ctxt_t* const ctxt_pP, const srb_flag_t srb_flagP,
+    const MBMS_flag_t MBMS_flagP, const rb_id_t rb_idP, const mui_t muiP,
+    confirm_t confirmP, sdu_size_t sdu_sizeP, mem_block_t *sdu_pP);
+
+void proto_agent_send_pdcp_data_ind(const protocol_ctxt_t* const ctxt_pP,
+    const srb_flag_t srb_flagP, const MBMS_flag_t MBMS_flagP,
+    const rb_id_t rb_idP, sdu_size_t sdu_sizeP, mem_block_t *sdu_pP);
+
 #endif
diff --git a/openair2/LAYER2/PROTO_AGENT/proto_agent_async.c b/openair2/LAYER2/PROTO_AGENT/proto_agent_async.c
index e4e165f945d1defefbdb2510914a0a38c2927c03..07c528da5bfc72a7228388234b4d0f80759243c2 100644
--- a/openair2/LAYER2/PROTO_AGENT/proto_agent_async.c
+++ b/openair2/LAYER2/PROTO_AGENT/proto_agent_async.c
@@ -95,7 +95,7 @@ proto_agent_async_channel_t * proto_server_async_channel_info(mod_id_t mod_id, c
 
  error:
   LOG_E(PROTO_AGENT,"there was an error\n");
-  return 1;
+  return NULL;
 }
 
 
@@ -154,12 +154,11 @@ proto_agent_async_channel_t * proto_agent_async_channel_info(mod_id_t mod_id, ch
 
  error:
   LOG_E(PROTO_AGENT,"there was an error\n");
-  return 1;
+  return NULL;
 }
 
 int proto_agent_async_msg_send(void *data, int size, int priority, void *channel_info) {
-  proto_agent_async_channel_t *channel;
-  channel = (proto_agent_channel_t *)channel_info;
+  proto_agent_async_channel_t *channel = channel_info;
 
   return message_put(channel->send_queue, data, size, priority);
 }
diff --git a/openair2/LAYER2/PROTO_AGENT/proto_agent_common.c b/openair2/LAYER2/PROTO_AGENT/proto_agent_common.c
index c8292658253e9cc192948bad01d86b9e3adbb819..d89c0b09ae0d21e591095f9cc737861a4b2b3b66 100644
--- a/openair2/LAYER2/PROTO_AGENT/proto_agent_common.c
+++ b/openair2/LAYER2/PROTO_AGENT/proto_agent_common.c
@@ -121,7 +121,7 @@ int f1u_dl_data_create_header(uint32_t pdu_type, uint32_t f1u_sn, Protocol__DlDa
   protocol__dl_data_header__init(*header);
   LOG_D(F1U, "Initialized the DL Data User header\n");
 
-  fill_dl_data_header(pdu_type, 0, f1u_sn, (*header)->fields);
+  fill_dl_data_header(pdu_type, 0, f1u_sn, &(*header)->fields);
   return 0;
 
  error:
@@ -149,7 +149,9 @@ int f1u_dl_data(const void *params, Protocol__F1uMessage **msg)
     goto error;
 
 
-  dl_data = *msg;
+  // FIXME: Is the following used? It seems to be overwritten by the function
+  // protocol__dl_user_data__init() anyway
+  //dl_data = *msg;
 
   protocol__dl_user_data__init(dl_data);
 
@@ -177,7 +179,7 @@ int f1u_dl_data(const void *params, Protocol__F1uMessage **msg)
   
 }
 
-int proto_agent_serialize_message(Protocol__FlexsplitMessage *msg, void **buf, int *size) {
+int proto_agent_serialize_message(Protocol__FlexsplitMessage *msg, uint8_t **buf, int *size) {
 
   *size = protocol__flexsplit_message__get_packed_size(msg);
 
@@ -238,7 +240,11 @@ int just_print(mod_id_t mod_id, const void *params, Protocol__FlexsplitMessage *
 
 int proto_agent_pdcp_data_req(mod_id_t mod_id, const void *params, Protocol__FlexsplitMessage **msg)
 {
-  
+  Protocol__FspCtxt *ctxt = NULL;
+  Protocol__FspRlcPdu *pdu = NULL;
+  Protocol__FspRlcData *rlc_data = NULL;
+  Protocol__FspRlcDataReq *data_req = NULL;
+
   // Initialize the PDCP params
   data_req_args *args = (data_req_args *)params;
  
@@ -255,11 +261,6 @@ int proto_agent_pdcp_data_req(mod_id_t mod_id, const void *params, Protocol__Fle
   *  2) Message fspRlcData is packing the packet + the context of the PDCP (separate message)
   *  3) Messge fspRlcDataReq is packing the header, enb_id and fspRlcData
   */
-  Protocol__FspCtxt *ctxt = NULL;
-  Protocol__FspRlcPdu *pdu = NULL;
-  Protocol__FspRlcData *rlc_data = NULL;
-  Protocol__FspRlcDataReq *data_req = NULL;
-  
 
   ctxt = malloc(sizeof(Protocol__FspCtxt));
   pdu = malloc(sizeof(Protocol__FspRlcPdu));
@@ -369,8 +370,6 @@ int proto_agent_destroy_pdcp_data_req(Protocol__FlexsplitMessage *msg) {
 
 int proto_agent_get_ack_result(mod_id_t mod_id, const void *params, Protocol__FlexsplitMessage **msg)
 {
-  Protocol__FspHeader *header;
-  xid_t xid;
   rlc_op_status_t result = 0;
   //printf("PROTO_AGENT: handling the data_req_ack message\n");
   Protocol__FlexsplitMessage *input = (Protocol__FlexsplitMessage *)params;
@@ -395,15 +394,12 @@ int proto_agent_pdcp_data_req_ack(mod_id_t mod_id, const void *params, Protocol_
   Protocol__FspRlcDataReq *data_req = input->data_req_msg;
   
   xid = data_req->header->xid;
-  Protocol__FspRlcPdu *pdu = NULL;
   Protocol__FspCtxt *ctxt = NULL;
   Protocol__FspRlcData *rlc_data = NULL;
   
   
   rlc_data = data_req->pdcp_data;
   
-  pdu = rlc_data->fsp_pdu;
-  
   ctxt = rlc_data->fsp_ctxt;
   
   protocol_ctxt_t	 *ctxt_pP;
@@ -451,11 +447,12 @@ int proto_agent_pdcp_data_req_ack(mod_id_t mod_id, const void *params, Protocol_
                         ,NULL
   #endif                      
                         );
+
+  Protocol__FspRlcDataReqAck *ack = NULL;
  
   if (fsp_create_header(xid, PROTOCOL__FSP_TYPE__FSPT_RLC_DATA_REQ_ACK, &header) != 0)
     goto error;
 
-  Protocol__FspRlcDataReqAck *ack = NULL;
   ack = malloc(sizeof(Protocol__FspRlcDataReqAck));
   protocol__fsp_rlc_data_req_ack__init(ack);
   
@@ -519,7 +516,11 @@ int proto_agent_destroy_pdcp_data_ind(Protocol__FlexsplitMessage *msg) {
 
 int proto_agent_pdcp_data_ind(mod_id_t mod_id, const void *params, Protocol__FlexsplitMessage **msg)
 {
-  
+  Protocol__FspCtxt *ctxt = NULL;
+  Protocol__FspRlcPdu *pdu = NULL;
+  Protocol__FspRlcData *rlc_data = NULL;
+  Protocol__FspPdcpDataInd *data_ind = NULL;
+
   // Initialize the PDCP params
   data_req_args *args = (data_req_args *)params;
  
@@ -536,12 +537,6 @@ int proto_agent_pdcp_data_ind(mod_id_t mod_id, const void *params, Protocol__Fle
   *  2) Message fspRlcData is packing the packet + the context of the PDCP (separate message)
   *  3) Messge fspRlcDataReq is packing the header, enb_id and fspRlcData
   */
-  
-  Protocol__FspCtxt *ctxt = NULL;
-  Protocol__FspRlcPdu *pdu = NULL;
-  Protocol__FspRlcData *rlc_data = NULL;
-  Protocol__FspPdcpDataInd *data_ind = NULL;
-  
 
   ctxt = malloc(sizeof(Protocol__FspCtxt));
   pdu = malloc(sizeof(Protocol__FspRlcPdu));
@@ -633,6 +628,8 @@ int proto_agent_pdcp_data_ind(mod_id_t mod_id, const void *params, Protocol__Fle
 int proto_agent_pdcp_data_ind_ack(mod_id_t mod_id, const void *params, Protocol__FlexsplitMessage **msg)
 {
   Protocol__FspHeader *header;
+  Protocol__FspPdcpDataIndAck *ack = NULL;
+
   xid_t xid;
   rlc_op_status_t result = 0;
   
@@ -642,15 +639,12 @@ int proto_agent_pdcp_data_ind_ack(mod_id_t mod_id, const void *params, Protocol_
   Protocol__FspPdcpDataInd *data_ind = input->data_ind_msg;
   
   xid = data_ind->header->xid;
-  Protocol__FspRlcPdu *pdu = NULL;
   Protocol__FspCtxt *ctxt = NULL;
   Protocol__FspRlcData *rlc_data = NULL;
   
   
   rlc_data = data_ind->rlc_data;
   
-  pdu = rlc_data->fsp_pdu;
-  
   ctxt = rlc_data->fsp_ctxt;
   
   protocol_ctxt_t	 *ctxt_pP;
@@ -687,11 +681,9 @@ int proto_agent_pdcp_data_ind_ack(mod_id_t mod_id, const void *params, Protocol_
 //   else if (xid == 0)   // FIXME: USE a preprocessed definition
     pdcp_data_ind((const protocol_ctxt_t*) ctxt_pP, (const srb_flag_t) srb_flagP, (const MBMS_flag_t) flag_MBMS, (const rb_id_t) rb_idP, pdcp_pdu_size, pdcp_pdu_p);
 
-
   if (fsp_create_header(xid, PROTOCOL__FSP_TYPE__FSPT_PDCP_DATA_IND_ACK, &header) != 0)
     goto error;
 
-  Protocol__FspPdcpDataIndAck *ack = NULL;
   ack = malloc(sizeof(Protocol__FspPdcpDataIndAck));
   protocol__fsp_pdcp_data_ind_ack__init(ack);
   
@@ -707,7 +699,9 @@ int proto_agent_pdcp_data_ind_ack(mod_id_t mod_id, const void *params, Protocol_
   (*msg)->msg_case = PROTOCOL__FLEXSPLIT_MESSAGE__MSG_DATA_IND_ACK;
   (*msg)->msg_dir = PROTOCOL__FLEXSPLIT_DIRECTION__SUCCESSFUL_OUTCOME;
   (*msg)->has_msg_dir = 1;
-  (*msg)->data_req_ack = ack;
+  // FIXME: the following was (*msg)->data_req_ack = ack;
+  // but this throws compiler warning. Probably we want the following instead
+  (*msg)->data_ind_ack = ack;
   
   return 0;
   
@@ -744,13 +738,14 @@ int proto_agent_destroy_pdcp_data_ind_ack(Protocol__FlexsplitMessage *msg) {
 int proto_agent_hello(mod_id_t mod_id, const void *params, Protocol__FlexsplitMessage **msg) {
  
   Protocol__FspHeader *header;
+  Protocol__FspHello *hello_msg = NULL;
+
   /*TODO: Need to set random xid or xid from received hello message*/
   xid_t xid = mod_id;
   if (fsp_create_header(xid, PROTOCOL__FSP_TYPE__FSPT_HELLO, &header) != 0)
     goto error;
 
   LOG_D(PROTO_AGENT, "creating the HELLO message\n");
-  Protocol__FspHello *hello_msg = NULL;
   hello_msg = malloc(sizeof(Protocol__FspHello));
   if(hello_msg == NULL)
     goto error;
@@ -797,13 +792,13 @@ int proto_agent_destroy_hello(Protocol__FlexsplitMessage *msg) {
 
 int proto_agent_echo_request(mod_id_t mod_id, const void* params, Protocol__FlexsplitMessage **msg) {
   Protocol__FspHeader *header;
+  Protocol__FspEchoRequest *echo_request_msg = NULL;
 
   xid_t xid = mod_id;
   if (fsp_create_header(xid, PROTOCOL__FSP_TYPE__FSPT_ECHO_REQUEST, &header) != 0)
     goto error;
   LOG_D(PROTO_AGENT, "creating the echo request message\n");
   
-  Protocol__FspEchoRequest *echo_request_msg = NULL;
   echo_request_msg = malloc(sizeof(Protocol__FspEchoRequest));
   if(echo_request_msg == NULL)
     goto error;
@@ -852,6 +847,7 @@ int proto_agent_echo_reply(mod_id_t mod_id, const void *params, Protocol__Flexsp
   xid_t xid;
   Protocol__FlexsplitMessage *input = (Protocol__FlexsplitMessage *)params;
   Protocol__FspEchoRequest *echo_req = input->echo_request_msg;
+  Protocol__FspEchoReply *echo_reply_msg = NULL;
   xid = (echo_req->header)->xid;
 
   
@@ -861,7 +857,6 @@ int proto_agent_echo_reply(mod_id_t mod_id, const void *params, Protocol__Flexsp
   if (fsp_create_header(xid, PROTOCOL__FSP_TYPE__FSPT_ECHO_REPLY, &header) != 0)
     goto error;
 
-  Protocol__FspEchoReply *echo_reply_msg;
   echo_reply_msg = malloc(sizeof(Protocol__FspEchoReply));
   if(echo_reply_msg == NULL)
     goto error;
diff --git a/openair2/LAYER2/PROTO_AGENT/proto_agent_common.h b/openair2/LAYER2/PROTO_AGENT/proto_agent_common.h
index 9421ee546fac2c53792e6b9f10976a6547674b44..d81561c14c77cf7355ebb5640b51cb3e9ae63748 100644
--- a/openair2/LAYER2/PROTO_AGENT/proto_agent_common.h
+++ b/openair2/LAYER2/PROTO_AGENT/proto_agent_common.h
@@ -78,11 +78,10 @@ uint32_t ack_result;
  * functions and generic handlers
  **********************************/
 
-int proto_agent_serialize_message(Protocol__FlexsplitMessage *msg, void **buf, int *size);
+int proto_agent_serialize_message(Protocol__FlexsplitMessage *msg, uint8_t **buf, int *size);
 int proto_agent_deserialize_message(void *data, int size, Protocol__FlexsplitMessage **msg);
 
-void * proto_agent_pack_message(Protocol__FlexsplitMessage *msg, 
-			      uint32_t * size);
+uint8_t *proto_agent_pack_message(Protocol__FlexsplitMessage *msg, int *size);
 
 err_code_t proto_agent_destroy_flexsplit_message(Protocol__FlexsplitMessage *msg);
 
@@ -112,7 +111,7 @@ int proto_agent_get_ack_result(mod_id_t mod_id, const void *params, Protocol__Fl
 
 Protocol__FlexsplitMessage* proto_agent_handle_message (mod_id_t mod_id, 
 						    uint8_t *data, 
-						    uint32_t size);
+						    int size);
 
 Protocol__FlexsplitMessage *proto_agent_handle_timed_task(void *args);
 
diff --git a/openair2/LAYER2/PROTO_AGENT/proto_agent_defs.h b/openair2/LAYER2/PROTO_AGENT/proto_agent_defs.h
index 33a2f48b95e557e8c237f476183c4c8c9f9bed90..2202390749031a24d065bb0c82b68f0acd5ebe66 100644
--- a/openair2/LAYER2/PROTO_AGENT/proto_agent_defs.h
+++ b/openair2/LAYER2/PROTO_AGENT/proto_agent_defs.h
@@ -49,7 +49,7 @@
 #define DEFAULT_PROTO_AGENT_PORT          2210
 #define DEFAULT_PROTO_AGENT_CACHE        "/mnt/oai_agent_cache"
 
-/*typedef enum {
+typedef enum {
   
   PROTO_AGENT_DEFAULT=0,
   
@@ -64,7 +64,7 @@
 
   ENB_AGENT_MAX=9,
     
-} agent_id_t;*/
+} proto_agent_id_t;
 
 /*
 typedef enum {
diff --git a/openair2/LAYER2/PROTO_AGENT/proto_agent_handler.c b/openair2/LAYER2/PROTO_AGENT/proto_agent_handler.c
index 7620a12a42afa9766ef93c9ea403b1ba5d099827..bfa4ed105ca0d419502d8dfd0c62b7f984ef5ea3 100644
--- a/openair2/LAYER2/PROTO_AGENT/proto_agent_handler.c
+++ b/openair2/LAYER2/PROTO_AGENT/proto_agent_handler.c
@@ -60,17 +60,17 @@ proto_agent_message_destruction_callback proto_message_destruction_callback[] =
 
 };
 
-static const char *proto_agent_direction2String[] = {
-  "", /* not_set  */
-  "originating message", /* originating message */
-  "successfull outcome", /* successfull outcome */
-  "unsuccessfull outcome", /* unsuccessfull outcome */
-};
+//static const char *proto_agent_direction2String[] = {
+//  "", /* not_set  */
+//  "originating message", /* originating message */
+//  "successfull outcome", /* successfull outcome */
+//  "unsuccessfull outcome", /* unsuccessfull outcome */
+//};
 
 
 Protocol__FlexsplitMessage* proto_agent_handle_message (mod_id_t mod_id,
 						    uint8_t *data, 
-						    uint32_t size){
+						    int size){
   
   Protocol__FlexsplitMessage *decoded_message = NULL;
   Protocol__FlexsplitMessage *reply_message = NULL;
@@ -117,9 +117,9 @@ Protocol__FlexsplitMessage* proto_agent_handle_message (mod_id_t mod_id,
 
 
 
-void * proto_agent_pack_message(Protocol__FlexsplitMessage *msg, 
-			      uint32_t * size){
-  void * buffer;
+uint8_t *proto_agent_pack_message(Protocol__FlexsplitMessage *msg, int *size)
+{
+  uint8_t *buffer;
   err_code_t err_code = PROTOCOL__FLEXSPLIT_ERR__NO_ERR;
   
   if (proto_agent_serialize_message(msg, &buffer, size) < 0 ) {
diff --git a/openair2/LAYER2/PROTO_AGENT/proto_agent_net_comm.c b/openair2/LAYER2/PROTO_AGENT/proto_agent_net_comm.c
index 6ae133c7fffd2686c17c522a5c3ca006a040b911..591a7ac2889fa75fd87adccaba240c28807cf97d 100644
--- a/openair2/LAYER2/PROTO_AGENT/proto_agent_net_comm.c
+++ b/openair2/LAYER2/PROTO_AGENT/proto_agent_net_comm.c
@@ -41,7 +41,7 @@ proto_agent_channel_t *agent_channel[NUM_MAX_ENB][ENB_AGENT_MAX];
 proto_agent_channel_instance_t channel_instance;
 int proto_agent_channel_id = 0;
 
-int proto_agent_msg_send(mod_id_t mod_id, agent_id_t agent_id, void *data, int size, int priority) {
+int proto_agent_msg_send(mod_id_t mod_id, proto_agent_id_t agent_id, void *data, int size, int priority) {
   /*Check if agent id is valid*/
   if (agent_id >= ENB_AGENT_MAX || agent_id < 0) {
     goto error;
@@ -61,7 +61,7 @@ int proto_agent_msg_send(mod_id_t mod_id, agent_id_t agent_id, void *data, int s
   return -1;
 }
 
-int proto_agent_msg_recv(mod_id_t mod_id, agent_id_t agent_id, void **data, int *size, int *priority) {
+int proto_agent_msg_recv(mod_id_t mod_id, proto_agent_id_t agent_id, void **data, int *size, int *priority) {
   /*Check if agent id is valid*/
   if (agent_id >= ENB_AGENT_MAX || agent_id < 0) {
     goto error;
@@ -81,7 +81,7 @@ int proto_agent_msg_recv(mod_id_t mod_id, agent_id_t agent_id, void **data, int
   return -1;
 }
 
-int proto_agent_register_channel(mod_id_t mod_id, proto_agent_channel_t *channel, agent_id_t agent_id) {
+int proto_agent_register_channel(mod_id_t mod_id, proto_agent_channel_t *channel, proto_agent_id_t agent_id) {
   int i;
 
   if (channel == NULL) {
@@ -98,7 +98,7 @@ int proto_agent_register_channel(mod_id_t mod_id, proto_agent_channel_t *channel
   return 0;
 }
 
-void proto_agent_unregister_channel(mod_id_t mod_id, agent_id_t agent_id) {
+void proto_agent_unregister_channel(mod_id_t mod_id, proto_agent_id_t agent_id) {
   int i;
 
   if (agent_id == ENB_AGENT_MAX) {
@@ -126,7 +126,7 @@ int proto_agent_create_channel(void *channel_info,
   /*element should be a real pointer*/
   RB_INSERT(proto_agent_channel_map, &channel_instance.proto_agent_head, channel); 
   
-  LOG_D(PROTO_AGENT,"Created a new channel with id 0x%lx\n", channel->channel_id);
+  LOG_D(PROTO_AGENT, "Created a new channel with id 0x%x\n", channel->channel_id);
  
   return channel_id; 
 }
@@ -150,7 +150,7 @@ int proto_agent_destroy_channel(int channel_id) {
     for (j = 0; j < ENB_AGENT_MAX; j++) {
       if (agent_channel[i][j] != NULL) {
 	if (agent_channel[i][j]->channel_id == e->channel_id) {
-	  agent_channel[i][j] == NULL;
+	  agent_channel[i][j] = NULL;
 	}
       }
     }
@@ -172,7 +172,7 @@ err_code_t proto_agent_init_channel_container(void) {
 
   for (i = 0; i < NUM_MAX_ENB; i++) {
     for (j = 0; j < ENB_AGENT_MAX; j++) {
-    agent_channel[i][j] == NULL;
+    agent_channel[i][j] = NULL;
     }
   }
 
diff --git a/openair2/LAYER2/PROTO_AGENT/proto_agent_net_comm.h b/openair2/LAYER2/PROTO_AGENT/proto_agent_net_comm.h
index 1224c0b914a11197fb3fc78a7968741a5d41d8b1..b489c64416130b04c08bbf2b079aec7d6143da95 100644
--- a/openair2/LAYER2/PROTO_AGENT/proto_agent_net_comm.h
+++ b/openair2/LAYER2/PROTO_AGENT/proto_agent_net_comm.h
@@ -35,7 +35,6 @@
  */
 #ifndef PROTO_AGENT_NET_COMM_H_
 #define PROTO_AGENT_NET_COMM_H_
-#include "ENB_APP/flexran_agent_defs.h"
 
 #include "proto_agent_defs.h"
 
@@ -59,16 +58,16 @@ typedef struct proto_agent_channel_instance_s{
 } proto_agent_channel_instance_t;
 
 /*Send and receive messages using the channel registered for a specific agent*/
-int proto_agent_msg_send(mod_id_t mod_id, agent_id_t agent_id, void *data, int size, int priority);
+int proto_agent_msg_send(mod_id_t mod_id, proto_agent_id_t agent_id, void *data, int size, int priority);
 
-int proto_agent_msg_recv(mod_id_t mod_id, agent_id_t agent_id, void **data, int *size, int *priority);
+int proto_agent_msg_recv(mod_id_t mod_id, proto_agent_id_t agent_id, void **data, int *size, int *priority);
 
 /*Register a channel to an agent. Use ENB_AGENT_MAX to register the
  *same channel to all agents*/
-int proto_agent_register_channel(mod_id_t mod_id, proto_agent_channel_t *channel, agent_id_t agent_id);
+int proto_agent_register_channel(mod_id_t mod_id, proto_agent_channel_t *channel, proto_agent_id_t agent_id);
 
 /*Unregister the current channel of an agent. Use ENB_AGENT_MAX to unregister all channels*/
-void proto_agent_unregister_channel(mod_id_t mod_id, agent_id_t agent_id);
+void proto_agent_unregister_channel(mod_id_t mod_id, proto_agent_id_t agent_id);
 
 /*Create a new channel. Returns the id of the new channel or negative number otherwise*/
 int proto_agent_create_channel(void *channel_info,
diff --git a/openair2/UTIL/ASYNC_IF/socket_link.c b/openair2/UTIL/ASYNC_IF/socket_link.c
index 8609b098113deb8c850b6a901a596181de6cbe60..8f06ed15ff5b5ba2d1b9d2fa48c6f3a75ac086ef 100644
--- a/openair2/UTIL/ASYNC_IF/socket_link.c
+++ b/openair2/UTIL/ASYNC_IF/socket_link.c
@@ -167,9 +167,8 @@ socket_link_t *new_link_udp_server(int port){
 
   socket_link_t  *ret = NULL;
 
-  struct sockaddr_in si_me, si_other;
-  int socket_server, i, slen = sizeof(si_other) , recv_bytes;
-  char buf[1500];
+  struct sockaddr_in si_me;
+  int socket_server = -1;
 
   ret = calloc(1, sizeof(socket_link_t));
   if (ret == NULL) {
@@ -201,7 +200,7 @@ socket_link_t *new_link_udp_server(int port){
   return ret;
   
 error:
-  close(socket_server);
+  if (socket_server != -1) close(socket_server);
   if (ret != NULL) close(ret->socket_fd);
   free(ret);
   //printf("\n\n\nERROR PROTO_AGENT: ERROR in new_link_udp_server (see above), returning NULL\n");
@@ -219,10 +218,9 @@ socket_link_t *new_link_udp_client(char *server, int port){
   }
   ret->socket_fd = -1;
 
-  struct sockaddr_in si_other, server_info;
-  int s, i, slen=sizeof(si_other);
-  char buf[1500];
-  char message[1500];
+  struct sockaddr_in si_other;
+  int s;
+  socklen_t slen;
  
   if ( (s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
         goto error;
@@ -258,14 +256,8 @@ socket_link_t *new_link_sctp_server(int port)
 {
 
   socket_link_t  *ret = NULL;
-  ret = calloc(1, sizeof(socket_link_t));
-  if (ret == NULL) {
-    LOG_D(PROTO_AGENT, "%s:%d: out of memory\n", __FILE__, __LINE__);
-    goto error;
-  }
-  ret->socket_fd = -1;
 
-  int listenSock, temp;
+  int listenSock = -1, temp;
   struct sockaddr_in servaddr;
  
   listenSock = socket (AF_INET, SOCK_STREAM, IPPROTO_SCTP);
@@ -296,13 +288,19 @@ socket_link_t *new_link_sctp_server(int port)
       close(listenSock);
       exit(1);
   }
+  ret = calloc(1, sizeof(socket_link_t));
+  if (ret == NULL) {
+    LOG_D(PROTO_AGENT, "%s:%d: out of memory\n", __FILE__, __LINE__);
+    goto error;
+  }
+  ret->socket_fd = -1;
 
-  ret->socket_fd = accept (listenSock, (struct sockaddr *) NULL, (int *) NULL);
+  ret->socket_fd = accept (listenSock, NULL, NULL);
   
   return ret;
 
 error:
-  close(listenSock);
+  if (listenSock != -1) close(listenSock);
   if (ret != NULL) close(ret->socket_fd);
   free(ret);
   LOG_E(MAC,"ERROR in new_link_sctp_server (see above), returning NULL\n");
@@ -399,13 +397,13 @@ static int socket_udp_receive(int socket_fd, void *buf, int size)
   LOG_D(PROTO_AGENT,"UDP RECEIVE\n");
 
   struct sockaddr_in client;
-  int slen = sizeof(client);
+  socklen_t slen;
   char *s = buf;
   int   l;
 
   while (size) {
     l = recvfrom(socket_fd, s, size, 0, (struct sockaddr *) &client, &slen);
-    getsockname(s, (struct sockaddr *)&client, &slen);
+    getsockname(socket_fd, (struct sockaddr *)&client, &slen);
     LOG_D(PROTO_AGENT, "Got message from src port: %u\n", ntohs(client.sin_port));
     if (l == -1) goto error;
     if (l == 0) goto socket_closed;
@@ -511,7 +509,7 @@ int link_send_packet(socket_link_t *link, void *data, int size, uint16_t proto_t
     if (socket_udp_send(link->socket_fd, sizebuf, 4, peer_addr, link->peer_port) == -1)
       goto error;
     
-    LOG_I(PROTO_AGENT,"sent %d bytes over the channel\n", (int32_t *)sizebuf);
+    LOG_I(PROTO_AGENT,"sent 4 bytes over the channel\n");
     link->bytes_sent += 4;
 
     if (socket_udp_send(link->socket_fd, data, size, peer_addr, link->peer_port) == -1)