diff --git a/openair1/PHY/TOOLS/nr_phy_scope.c b/openair1/PHY/TOOLS/nr_phy_scope.c
index 40803c30f4fc7486989f05aaf08b62ea13cb64e4..e0fa894d92f90c5f6a8289808cf31693d060f260 100644
--- a/openair1/PHY/TOOLS/nr_phy_scope.c
+++ b/openair1/PHY/TOOLS/nr_phy_scope.c
@@ -157,9 +157,9 @@ void phy_scope_gNB(FD_phy_scope_gnb *form,
 {
   int i, arx; //int i,i2,arx,atx,ind,k;
   NR_DL_FRAME_PARMS *frame_parms = &phy_vars_gnb->frame_parms;
-  int nsymb_ce = 12*frame_parms->N_RB_UL*frame_parms->symbols_per_tti;
+  //int nsymb_ce = 12*frame_parms->N_RB_UL*frame_parms->symbols_per_tti;
   uint8_t nb_antennas_rx = frame_parms->nb_antennas_rx;
-  uint8_t nb_antennas_tx = 1; // frame_parms->nb_antennas_tx; // in LTE Rel. 8 and 9 only a single transmit antenna is assumed at the UE
+  //uint8_t nb_antennas_tx = 1; // frame_parms->nb_antennas_tx; // in LTE Rel. 8 and 9 only a single transmit antenna is assumed at the UE
   int16_t **rxsig_t, **rxsig_f;
   // int16_t **chest_t=NULL;
   // int16_t **chest_f=NULL;
@@ -966,7 +966,7 @@ FD_stats_form * create_form_stats_form( void ) {
 }
 
 void startScope(scopeParms_t * p) {
-  FD_stats_form *form_stats=NULL,*form_stats_l2=NULL;
+  //FD_stats_form *form_stats=NULL,*form_stats_l2=NULL;
   char title[255];
   fl_initialize (p->argc, p->argv, NULL, 0, 0);
   /*
diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
index 6191676d88c1b0144a77ac8a81aa1caac0ec9ea3..801a135782b1fb4e401adb9e46abd0101224f810 100644
--- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
+++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
@@ -3127,8 +3127,8 @@ void nr_process_rar(nr_downlink_indication_t *dl_info) {
 
   module_id_t module_id = dl_info->module_id;
   int cc_id = dl_info->cc_id, frame_rx = dl_info->proc->frame_rx, nr_tti_rx = dl_info->proc->nr_tti_rx, ta_command, k2, delta;
-  uint8_t gNB_index = dl_info->gNB_index, *rar;
-  fapi_nr_dci_indication_t *dci_ind = dl_info->dci_ind;
+  uint8_t gNB_index = dl_info->gNB_index; // *rar;
+  //fapi_nr_dci_indication_t *dci_ind = dl_info->dci_ind;
   PHY_VARS_NR_UE *ue = PHY_vars_UE_g[module_id][cc_id];
   NR_UE_DLSCH_t *dlsch0 = ue->dlsch_ra[gNB_index];
   UE_MODE_t UE_mode = ue->UE_mode[gNB_index];
@@ -3182,7 +3182,7 @@ void nr_process_rar(nr_downlink_indication_t *dl_info) {
 
         nr_process_timing_advance_rar(ue, dl_info->proc, ta_command);
 
-        if (UE_mode != debug_prach) {
+        if (ue->mode != debug_prach) {
           ue->ulsch_Msg3_active[gNB_index] = 1;
           // TS 38.213 ch 8.3 Msg3 PUSCH
           // PUSCH time domain resource allocation A for normal CP
@@ -3551,6 +3551,8 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
         case PDSCH:
         rx_ind.rx_indication_body[0].pdu_type = FAPI_NR_RX_PDU_TYPE_DLSCH;
         break;
+        default:
+        break;
       }
 
       rx_ind.rx_indication_body[0].pdsch_pdu.pdu = dlsch0->harq_processes[harq_pid]->b;
diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h
index 24ffb7347f2a54abb0ceeab35cfa5f858b1f6399..580e3c438d225bb2ee3208b9958ae4493c8b9afe 100755
--- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h
+++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h
@@ -194,6 +194,8 @@ int8_t nr_get_Po_NOMINAL_PUSCH(NR_PRACH_RESOURCES_t *prach_resources, module_id_
 */
 int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id);
 
+/* Random Access */
+
 /* \brief Function called by PHY to process the received RAR and check that the preamble matches what was sent by the gNB. It provides the timing advance and t-CRNTI.
 @param Mod_id Index of UE instance
 @param CC_id Index to a component carrier
@@ -220,5 +222,45 @@ void ue_contention_resolution(module_id_t module_id, uint8_t gNB_index, int cc_i
 
 void nr_ra_failed(uint8_t Mod_id, uint8_t CC_id, uint8_t gNB_index);
 
+void nr_ra_succeeded(uint8_t Mod_id, uint8_t CC_id, uint8_t gNB_index);
+
+/* \brief Function called by PHY to retrieve information to be transmitted using the RA procedure.
+If the UE is not in PUSCH mode for a particular eNB index, this is assumed to be an Msg3 and MAC
+attempts to retrieves the CCCH message from RRC. If the UE is in PUSCH mode for a particular eNB
+index and PUCCH format 0 (Scheduling Request) is not activated, the MAC may use this resource for
+andom-access to transmit a BSR along with the C-RNTI control element (see 5.1.4 from 36.321)
+@param mod_id Index of UE instance
+@param CC_id Component Carrier Index
+@param frame
+@param gNB_id gNB index
+@param nr_tti_tx slot for PRACH transmission
+@returns void */
+void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
+                    module_id_t mod_id,
+                    int CC_id,
+                    UE_MODE_t UE_mode,
+                    frame_t frame,
+                    uint8_t gNB_id,
+                    int nr_tti_tx);
+
+/* \brief Function implementing the routine for the selection of Random Access resources (5.1.2 TS 38.321).
+@param module_idP Index of UE instance
+@param CC_id Component Carrier Index
+@param gNB_index gNB index
+@param t_id
+@param rach_ConfigDedicated
+@returns void */
+void nr_get_prach_resources(module_id_t mod_id,
+                            int CC_id,
+                            uint8_t gNB_id,
+                            uint8_t t_id,
+                            uint8_t first_Msg3,
+                            NR_PRACH_RESOURCES_t *prach_resources,
+                            NR_RACH_ConfigDedicated_t * rach_ConfigDedicated);
+
+void nr_Msg1_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, uint8_t gNB_id);
+
+void nr_Msg3_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, uint8_t gNB_id);
+
 #endif
 /** @}*/
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c b/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c
index 20113f494c4b635b38dd6702a41e0bbd82e44460..e61e58c7647ba087bd2cfc42d9ecdf09f2ee0a91 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c
@@ -33,6 +33,7 @@
 
 #include "mac_defs.h"
 #include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h"
+#include "LAYER2/NR_MAC_UE/mac_proto.h"
 
 // WIP todo:
 //- frame_type and fr are hardcoded. Retireve from fp
@@ -52,7 +53,7 @@ int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id){
 
     // SCS configuration from msg1_SubcarrierSpacing and table 4.2-1 in TS 38.211
 
-    NR_SubcarrierSpacing_t scs = nr_rach_ConfigCommon->msg1_SubcarrierSpacing;
+    NR_SubcarrierSpacing_t scs = *nr_rach_ConfigCommon->msg1_SubcarrierSpacing;
 
     switch (scs){
       case NR_SubcarrierSpacing_kHz15:
@@ -88,7 +89,7 @@ int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id){
       break;
 
       default:
-      AssertFatal(1 == 0,"Unknown msg1_SubcarrierSpacing %d\n", scs);
+      AssertFatal(1 == 0,"Unknown msg1_SubcarrierSpacing %lu\n", scs);
     }
 
     // Preamble formats given by prach_ConfigurationIndex and tables 6.3.3.2-2 and 6.3.3.2-2 in TS 38.211
@@ -131,7 +132,6 @@ int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id){
       default:
       AssertFatal(1 == 0, "[UE %d] ue_procedures.c: FATAL, Illegal preambleFormat %d, prachConfigIndex %d\n", mod_id, preambleFormat, prachConfigIndex);
     }
-    return;
 }
 
 /* TS 38.321 subclause 5.1.3 - RA preamble transmission - ra_PREAMBLE_RECEIVED_TARGET_POWER configuration */
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
index 142ef097d010c6cd8b801742e858f49d2bf35c27..eaaa47df257854a2318100145398bd1ea1771907 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
@@ -55,6 +55,7 @@
 #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
 #include "PHY/defs_common.h"
 #include "PHY/defs_nr_common.h"
+#include "PHY/NR_UE_ESTIMATION/nr_estimation.h"
 
 /* MAC */
 #include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h"
@@ -81,7 +82,7 @@ void nr_get_prach_resources(module_id_t mod_id,
   NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon;
   // NR_BeamFailureRecoveryConfig_t *beam_failure_recovery_config = &mac->RA_BeamFailureRecoveryConfig; // todo
 
-  int messagePowerOffsetGroupB, messageSizeGroupA, PLThreshold, sizeOfRA_PreamblesGroupA, numberOfRA_Preambles, frequencyStart, i, deltaPreamble_Msg3;
+  int messagePowerOffsetGroupB, messageSizeGroupA, PLThreshold, sizeOfRA_PreamblesGroupA, numberOfRA_Preambles, i, deltaPreamble_Msg3;
   uint8_t noGroupB = 0, s_id, f_id, ul_carrier_id, msg1_FDM, prach_ConfigIndex, SFN_nbr, Msg3_size;
 
   // NR_RSRP_Range_t rsrp_ThresholdSSB; // todo
@@ -120,7 +121,7 @@ void nr_get_prach_resources(module_id_t mod_id,
   nr_rach_ConfigCommon = mac->nr_rach_ConfigCommon;
 
   Msg3_size = mac->RA_Msg3_size;
-  numberOfRA_Preambles = nr_rach_ConfigCommon->totalNumberOfRA_Preambles;
+  numberOfRA_Preambles = *nr_rach_ConfigCommon->totalNumberOfRA_Preambles;
 
   if (!nr_rach_ConfigCommon->groupBconfigured) {
     noGroupB = 1;
@@ -161,7 +162,7 @@ void nr_get_prach_resources(module_id_t mod_id,
     messageSizeGroupA = 72;
     break;
     default:
-    AssertFatal(1 == 0,"Unknown ra_Msg3SizeGroupA %d\n", nr_rach_ConfigCommon->groupBconfigured->ra_Msg3SizeGroupA);
+    AssertFatal(1 == 0,"Unknown ra_Msg3SizeGroupA %lu\n", nr_rach_ConfigCommon->groupBconfigured->ra_Msg3SizeGroupA);
     /* todo cases 10 -15*/
     }
 
@@ -193,7 +194,7 @@ void nr_get_prach_resources(module_id_t mod_id,
     messagePowerOffsetGroupB = 18;
     break;
     default:
-    AssertFatal(1 == 0,"Unknown messagePowerOffsetGroupB %d\n", nr_rach_ConfigCommon->groupBconfigured->messagePowerOffsetGroupB);
+    AssertFatal(1 == 0,"Unknown messagePowerOffsetGroupB %lu\n", nr_rach_ConfigCommon->groupBconfigured->messagePowerOffsetGroupB);
     }
 
     // todo Msg3-DeltaPreamble should be provided from higher layers, otherwise is 0
@@ -222,7 +223,9 @@ void nr_get_prach_resources(module_id_t mod_id,
       mac->RA_usedGroupA = 0;
     }
   } else { // Msg3 is being retransmitted
-    if (mac->RA_usedGroupA == 1) {
+    if (mac->RA_usedGroupA == 1 && noGroupB == 1) {
+      prach_resources->ra_PreambleIndex = (taus()) % numberOfRA_Preambles;
+    } else if (mac->RA_usedGroupA == 1 && noGroupB == 0){
       prach_resources->ra_PreambleIndex = (taus()) % sizeOfRA_PreamblesGroupA;
     } else {
       prach_resources->ra_PreambleIndex = sizeOfRA_PreamblesGroupA + (taus()) % (numberOfRA_Preambles - sizeOfRA_PreamblesGroupA);
@@ -265,7 +268,7 @@ void nr_get_prach_resources(module_id_t mod_id,
     msg1_FDM = 8;
     break;
     default:
-    AssertFatal(1 == 0,"Unknown msg1_FDM %d\n", nr_rach_ConfigCommon->rach_ConfigGeneric.msg1_FDM);
+    AssertFatal(1 == 0,"Unknown msg1_FDM %lu\n", nr_rach_ConfigCommon->rach_ConfigGeneric.msg1_FDM);
    }
 
    prach_ConfigIndex = nr_rach_ConfigCommon->rach_ConfigGeneric.prach_ConfigurationIndex;
@@ -299,7 +302,7 @@ void nr_get_prach_resources(module_id_t mod_id,
 void nr_Msg1_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, uint8_t gNB_id){
   AssertFatal(CC_id == 0, "Transmission on secondary CCs is not supported yet\n");
   NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id);
-  mac->ra_state == WAIT_RAR;
+  mac->ra_state = WAIT_RAR;
   // Start contention resolution timer
   mac->RA_attempt_number++;
 }
@@ -342,11 +345,11 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
                     int nr_tti_tx){
 
   NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id);
-  uint8_t lcid = UL_SCH_LCID_CCCH_MSG3, dcch_header_len = 0, *mac_sdus, *payload, ra_ResponseWindow;
+  uint8_t lcid = UL_SCH_LCID_CCCH_MSG3, *mac_sdus, *payload, ra_ResponseWindow;
   uint16_t size_sdu = 0;
   unsigned short post_padding;
-  NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon = (struct NR_RACH_ConfigCommon_t *) NULL;
-  int32_t frame_diff = 0;
+  NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon = (NR_RACH_ConfigCommon_t *) NULL;
+  // int32_t frame_diff = 0;
 
   uint8_t sdu_lcids[NB_RB_MAX] = {0};
   uint16_t sdu_lengths[NB_RB_MAX] = {0};
@@ -391,7 +394,7 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
       prach_resources->RA_SCALING_FACTOR_BI = 1;
       prach_resources->RA_PCMAX = 0; // currently hardcoded to 0
 
-      payload = &mac->CCCH_pdu.payload;
+      payload = (uint8_t*) &mac->CCCH_pdu.payload;
 
       mac_ce_len = 0;
       num_sdus = 1;
@@ -400,7 +403,7 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
       if (!IS_SOFTMODEM_NOS1){
         // initialisation by RRC
         // CCCH PDU
-        mac_sdus = payload[sizeof(NR_MAC_SUBHEADER_SHORT)];
+        mac_sdus = &payload[sizeof(NR_MAC_SUBHEADER_SHORT)];
         size_sdu = (uint16_t) mac_rrc_data_req_ue(mod_id,
                                                   CC_id,
                                                   frame,
@@ -470,7 +473,7 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
         }
 
         // Fill in preamble and PRACH resources
-        nr_get_prach_resources(prach_resources, mod_id, CC_id, gNB_id, nr_tti_tx, 1, NULL);
+        nr_get_prach_resources(mod_id, CC_id, gNB_id, nr_tti_tx, 1, prach_resources, NULL);
 
         offset = nr_generate_ulsch_pdu((uint8_t *) mac_sdus,              // sdus buffer
                                        (uint8_t *) payload,               // UL MAC pdu pointer
@@ -514,7 +517,7 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
       }
 
       if (mac->RA_window_cnt > 0  && mac->RA_RAPID_found == 1) {
-        mac->ra_state == WAIT_CONTENTION_RESOLUTION;
+        mac->ra_state = WAIT_CONTENTION_RESOLUTION;
       } else {
         LOG_I(MAC, "[MAC][UE %d][RAPROC] Frame %d: subframe %d: RAR reception not successful, (RA window count %d) \n",
           mod_id,
@@ -565,7 +568,7 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
           LOG_D(MAC, "[UE %d] Frame %d: Maximum number of RACH attempts (%d)\n", mod_id, frame, preambleTransMax);
           mac->RA_backoff_cnt = rand() % (prach_resources->RA_PREAMBLE_BACKOFF + 1);
           mac->RA_PREAMBLE_TRANSMISSION_COUNTER = 1;
-          prach_resources->RA_PREAMBLE_POWER_RAMPING_STEP << 1; // 2 dB increment
+          prach_resources->RA_PREAMBLE_POWER_RAMPING_STEP += prach_resources->RA_PREAMBLE_POWER_RAMPING_STEP << 1; // 2 dB increment
           prach_resources->ra_PREAMBLE_RECEIVED_TARGET_POWER = nr_get_Po_NOMINAL_PUSCH(prach_resources, mod_id, CC_id);
         }
 
@@ -587,7 +590,7 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
         mac->RA_tx_frame = frame;
         mac->RA_tx_subframe = nr_tti_tx;
         // Fill in preamble and PRACH resources
-        nr_get_prach_resources(prach_resources, mod_id, CC_id, gNB_id, nr_tti_tx, 0, NULL);
+        nr_get_prach_resources(mod_id, CC_id, gNB_id, nr_tti_tx, 0, prach_resources, NULL);
         return;
       }
     }
@@ -595,5 +598,6 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
     LOG_D(MAC, "[UE %d] FATAL: Should not have checked for RACH in PUSCH yet ...", mod_id);
     AssertFatal(1 == 0, "");
   }
- return prach_resources = NULL;
+ prach_resources = NULL;
+ return;
 }
\ No newline at end of file
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c
index 421c8eb75b7c1eb6fd1377b601beb17f3f357979..8c3ccfce5e34a15386c7c49b4a515c90d4d1774f 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c
@@ -35,6 +35,7 @@
 #include "assertions.h"
 #include "LAYER2/NR_MAC_UE/mac_extern.h"
 #include "mac_defs.h"
+#include "common/utils/nr/nr_common.h"
 #include <stdio.h>
 
 #ifdef NR_PDCCH_DCI_TOOLS_DEBUG
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
index 8219a96ea2104233728c92541e129b9409e1fa6d..0cd4c27c306d2968d287c207936b26364eb4eb28 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
@@ -37,6 +37,9 @@
 /* exe */
 #include "executables/nr-softmodem.h"
 
+/* RRC*/
+#include "RRC/NR_UE/rrc_proto.h"
+
 /* MAC */
 #include "mac_defs.h"
 #include "NR_MAC_COMMON/nr_mac.h"
@@ -746,11 +749,11 @@ NR_UE_L2_STATE_t nr_ue_scheduler(const module_id_t module_id,
 void ue_contention_resolution(module_id_t module_id, uint8_t gNB_index, int cc_id, frame_t tx_frame){
   
   NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
-  NR_RACH_ConfigCommon_t *rach_ConfigCommon;
+  NR_RACH_ConfigCommon_t *rach_ConfigCommon = (NR_RACH_ConfigCommon_t *) NULL;
 
   if (mac->RA_contention_resolution_timer_active == 1) {
     if (mac->nr_rach_ConfigCommon) {
-      rach_ConfigCommon = &mac->nr_rach_ConfigCommon;
+      rach_ConfigCommon = mac->nr_rach_ConfigCommon;
     } else {
       // LOG_E(MAC, "FATAL: radioResourceConfigCommon is NULL!!!\n");
       // VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SCHEDULER,VCD_FUNCTION_OUT);
@@ -761,19 +764,21 @@ void ue_contention_resolution(module_id_t module_id, uint8_t gNB_index, int cc_i
       // #endif
     }
 
-    LOG_I(MAC, "Frame %d: Contention resolution timer %d/%ld\n", 
-      tx_frame,
-      mac->RA_contention_resolution_cnt,
-      ((1 + rach_ConfigCommon->ra_ContentionResolutionTimer) << 3));
-      mac->RA_contention_resolution_cnt++;
-
-    if (mac->RA_contention_resolution_cnt == ((1 + rach_ConfigCommon->ra_ContentionResolutionTimer) << 3)) {
-      mac->t_crnti = 0;
-      mac->RA_active = 0;
-      mac->RA_contention_resolution_timer_active = 0;
-      // Signal PHY to quit RA procedure
-      LOG_E(MAC, "[UE %u] [RAPROC] Contention resolution timer expired, RA failed, discarded TC-RNTI\n", module_id);
-      nr_ra_failed(module_id, cc_id, gNB_index);
+    if (rach_ConfigCommon){
+      LOG_I(MAC, "Frame %d: Contention resolution timer %d/%ld\n",
+        tx_frame,
+        mac->RA_contention_resolution_cnt,
+        ((1 + rach_ConfigCommon->ra_ContentionResolutionTimer) << 3));
+        mac->RA_contention_resolution_cnt++;
+
+      if (mac->RA_contention_resolution_cnt == ((1 + rach_ConfigCommon->ra_ContentionResolutionTimer) << 3)) {
+        mac->t_crnti = 0;
+        mac->RA_active = 0;
+        mac->RA_contention_resolution_timer_active = 0;
+        // Signal PHY to quit RA procedure
+        LOG_E(MAC, "[UE %u] [RAPROC] Contention resolution timer expired, RA failed, discarded TC-RNTI\n", module_id);
+        nr_ra_failed(module_id, cc_id, gNB_index);
+      }
     }
   }
 }
@@ -1958,7 +1963,7 @@ int nr_ue_process_dci_indication_pdu(module_id_t module_id,int cc_id, int gNB_in
 	dci->rnti,dci->dci_format,dci->n_CCE,dci->payloadSize,*(unsigned long long*)dci->payloadBits);
 
   nr_extract_dci_info(mac,dci->dci_format,dci->payloadSize,dci->rnti,(uint64_t *)dci->payloadBits,&dci_pdu_rel15);
-  nr_ue_process_dci(module_id, cc_id, gNB_index, &dci_pdu_rel15, dci->rnti, dci->dci_format);
+  return (nr_ue_process_dci(module_id, cc_id, gNB_index, &dci_pdu_rel15, dci->rnti, dci->dci_format));
 }
 
 int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, nr_dci_pdu_rel15_t *dci, uint16_t rnti, uint32_t dci_format){
@@ -2718,7 +2723,6 @@ void nr_ue_send_sdu(module_id_t module_idP,
   LOG_D(MAC, "Handling PDU frame %d slot %d\n", frameP, slotP);
 
   uint8_t * pduP = pdu;
-  NR_UE_MAC_INST_t *UE_mac_inst = get_mac_inst(module_idP);
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SEND_SDU, VCD_FUNCTION_IN);
 
@@ -3370,7 +3374,7 @@ unsigned char nr_generate_ulsch_pdu(uint8_t *sdus_payload,
                                     unsigned short post_padding) {
 
   NR_MAC_SUBHEADER_FIXED *mac_pdu_ptr = (NR_MAC_SUBHEADER_FIXED *) pdu;
-  unsigned char first_element = 0, last_size = 0, i, mac_header_control_elements[16], *ce_ptr, bsr = 0;
+  unsigned char last_size = 0, i, mac_header_control_elements[16], *ce_ptr, bsr = 0;
   int mac_ce_size, offset;
 
   LOG_D(MAC, "[UE] Generating ULSCH PDU : num_sdus %d\n", num_sdus);
diff --git a/openair2/LAYER2/NR_MAC_UE/rar_tools_nrUE.c b/openair2/LAYER2/NR_MAC_UE/rar_tools_nrUE.c
index a9f304fe2beacb6c635742ba2330ee71dfec27e4..f0ba7892661b081d5db93284b5b53ce48525b286 100644
--- a/openair2/LAYER2/NR_MAC_UE/rar_tools_nrUE.c
+++ b/openair2/LAYER2/NR_MAC_UE/rar_tools_nrUE.c
@@ -48,21 +48,21 @@
 #define DEBUG_RAR
 
 // table 7.2-1 TS 38.321
-uint8_t table_7_2_1[16] = {
-  {5},    // row index 0
-  {10},   // row index 1
-  {20},   // row index 2
-  {30},   // row index 3
-  {40},   // row index 4
-  {60},   // row index 5
-  {80},   // row index 6
-  {120},  // row index 7
-  {160},  // row index 8
-  {240},  // row index 9
-  {320},  // row index 10
-  {480},  // row index 11
-  {960},  // row index 12
-  {1920}, // row index 13
+uint16_t table_7_2_1[16] = {
+  5,    // row index 0
+  10,   // row index 1
+  20,   // row index 2
+  30,   // row index 3
+  40,   // row index 4
+  60,   // row index 5
+  80,   // row index 6
+  120,  // row index 7
+  160,  // row index 8
+  240,  // row index 9
+  320,  // row index 10
+  480,  // row index 11
+  960,  // row index 12
+  1920, // row index 13
 };
 
 // WIP todo:
@@ -89,7 +89,7 @@ uint16_t nr_ue_process_rar(module_id_t mod_id,
       n_subheaders++;
       if (rarh->T == 1) {
         n_subPDUs++;
-        LOG_D(MAC, "[UE %d][RAPROC] Got RAPID RAR subPDU %d\n", mod_id, rarh->RAPID);
+        LOG_D(MAC, "[UE %d][RAPROC] Got RAPID RAR subPDU\n", mod_id);
       } else {
         n_subPDUs++;
         ue_mac->RA_backoff_indicator = table_7_2_1[((NR_RA_HEADER_BI *)rarh)->BI];
@@ -97,7 +97,7 @@ uint16_t nr_ue_process_rar(module_id_t mod_id,
         LOG_D(MAC, "[UE %d][RAPROC] Got BI RAR subPDU %d\n", mod_id, ue_mac->RA_backoff_indicator);
       }
       if (rarh->RAPID == preamble_index) {
-        LOG_D(PHY, "[UE %d][RAPROC] Found RAR with the intended RAPID %d\n", rarh->RAPID);
+        LOG_D(PHY, "[UE %d][RAPROC] Found RAR with the intended RAPID %d\n", mod_id, rarh->RAPID);
         rar = (NR_MAC_RAR *) (dlsch_buffer + n_subheaders + (n_subPDUs - 1) * sizeof(NR_MAC_RAR));
         ue_mac->RA_RAPID_found = 1;
         break;
@@ -116,13 +116,13 @@ uint16_t nr_ue_process_rar(module_id_t mod_id,
 
     LOG_D(MAC, "number of RAR subheader %d; number of RAR pyloads %d\n", n_subheaders, n_subPDUs);
 
-    LOG_I(MAC, "[UE %d][RAPROC] Frame %d Received RAR (%02x|%02x.%02x.%02x.%02x.%02x.%02x) for preamble %d/%d\n",
-      mod_id, frameP, *(uint8_t *) rarh, rar[0], rar[1], rar[2], rar[3], rar[4], rar[5], rarh->RAPID, preamble_index);
+    // LOG_I(MAC, "[UE %d][RAPROC] Frame %d Received RAR (%02x|%02x.%02x.%02x.%02x.%02x.%02x) for preamble %d/%d\n",
+    //   mod_id, frameP, *(uint8_t *) rarh, rar[0], rar[1], rar[2], rar[3], rar[4], rar[5], rarh->RAPID, preamble_index);
 
     if (ue_mac->RA_RAPID_found) {
       *t_crnti = rar->TCRNTI_2 + (rar->TCRNTI_1 << 8);
       ue_mac->t_crnti = *t_crnti;
-      ue_mac->rnti_type == NR_RNTI_TC;
+      ue_mac->rnti_type = NR_RNTI_TC;
       ta_command = rar->TA2 + (rar->TA1 << 5);
     } else {
       ue_mac->t_crnti = 0;
diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
index 092a2df94c5a56a2adbf9f3bbc6c0b955f881d5d..89bb3e3f2c759e65d73e219c952060f0a0fbfd90 100644
--- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
+++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
@@ -259,44 +259,4 @@ void nr_rx_sdu(const module_id_t gnb_mod_idP,
                const uint16_t sdu_lenP,
                const uint16_t timing_advance, const uint8_t ul_cqi);
 
-/* Random Access */ 
-
-/* \brief Function called by PHY to retrieve information to be transmitted using the RA procedure. 
-If the UE is not in PUSCH mode for a particular eNB index, this is assumed to be an Msg3 and MAC 
-attempts to retrieves the CCCH message from RRC. If the UE is in PUSCH mode for a particular eNB 
-index and PUCCH format 0 (Scheduling Request) is not activated, the MAC may use this resource for 
-andom-access to transmit a BSR along with the C-RNTI control element (see 5.1.4 from 36.321)
-@param mod_id Index of UE instance
-@param CC_id Component Carrier Index
-@param frame
-@param gNB_id gNB index
-@param nr_tti_tx slot for PRACH transmission
-@returns void */
-void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
-                    module_id_t mod_id,
-                    int CC_id,
-                    UE_MODE_t UE_mode,
-                    frame_t frame,
-                    uint8_t gNB_id,
-                    int nr_tti_tx);
-
-/* \brief Function implementing the routine for the selection of Random Access resources (5.1.2 TS 38.321).
-@param module_idP Index of UE instance
-@param CC_id Component Carrier Index
-@param gNB_index gNB index
-@param t_id 
-@param rach_ConfigDedicated 
-@returns void */
-void nr_get_prach_resources(module_id_t mod_id, 
-                            int CC_id,
-                            uint8_t gNB_id,
-                            uint8_t t_id,
-                            uint8_t first_Msg3,
-                            NR_PRACH_RESOURCES_t *prach_resources,
-                            NR_RACH_ConfigDedicated_t * rach_ConfigDedicated);
-
-void nr_Msg1_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, uint8_t gNB_id);
-
-void nr_Msg3_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, uint8_t gNB_id);
-
 #endif /*__LAYER2_NR_MAC_PROTO_H__*/