diff --git a/executables/nr-ru.c b/executables/nr-ru.c
index bec4f82d2acf4d45e05c8e5f52f462676e8f230d..ed9744b5ae6f34cf2b8917e8d89e5a8474524ff0 100644
--- a/executables/nr-ru.c
+++ b/executables/nr-ru.c
@@ -1215,7 +1215,7 @@ static void *ru_thread_tx( void *param ) {
   
   if(ru->if_south == LOCAL_RF)
   {
-    uhd_set_thread_prio();
+    //uhd_set_thread_prio();
     LOG_I(PHY,"set ru_thread_tx uhd priority");
   }
 
diff --git a/executables/nr-ue.c b/executables/nr-ue.c
index a2a0bf11615e37df9fc91765a8ada1ac9d22880b..63f588519c621bcf98d57d916444abaa7dba2dc2 100644
--- a/executables/nr-ue.c
+++ b/executables/nr-ue.c
@@ -350,39 +350,42 @@ static void UE_synch(void *arg) {
 }
 
 void processSlotRX( PHY_VARS_NR_UE *UE, UE_nr_rxtx_proc_t *proc) {
+
+  nr_dcireq_t dcireq;
+  nr_scheduled_response_t scheduled_response;
+
   // Process Rx data for one sub-frame
   if (slot_select_nr(&UE->frame_parms, proc->frame_tx, proc->nr_tti_tx) & NR_DOWNLINK_SLOT) {
-    //clean previous FAPI MESSAGE
-    UE->rx_ind.number_pdus = 0;
-    UE->dci_ind.number_of_dcis = 0;
-    //clean previous FAPI MESSAGE
-    // call L2 for DL_CONFIG (DCI)
-    UE->dcireq.module_id = UE->Mod_id;
-    UE->dcireq.gNB_index = 0;
-    UE->dcireq.cc_id     = 0;
-    UE->dcireq.frame     = proc->frame_rx;
-    UE->dcireq.slot      = proc->nr_tti_rx;
-    nr_ue_dcireq(&UE->dcireq); //to be replaced with function pointer later
-    NR_UE_MAC_INST_t *UE_mac = get_mac_inst(0);
-    UE_mac->scheduled_response.dl_config = &UE->dcireq.dl_config_req;
-    UE_mac->scheduled_response.ul_config = NULL;
-    UE_mac->scheduled_response.tx_request = NULL;
-    UE_mac->scheduled_response.module_id = UE->Mod_id;
-    UE_mac->scheduled_response.CC_id     = 0;
-    UE_mac->scheduled_response.frame = proc->frame_rx;
-    UE_mac->scheduled_response.slot  = proc->nr_tti_rx;
-    nr_ue_scheduled_response(&UE_mac->scheduled_response);
-    //write_output("uerxdata_frame.m", "uerxdata_frame", UE->common_vars.rxdata[0], UE->frame_parms.samples_per_frame, 1, 1);
+    //TODO: all of this has to be moved to the MAC!!!
+    dcireq.module_id = UE->Mod_id;
+    dcireq.gNB_index = 0;
+    dcireq.cc_id     = 0;
+    dcireq.frame     = proc->frame_rx;
+    dcireq.slot      = proc->nr_tti_rx;
+    nr_ue_dcireq(&dcireq); //to be replaced with function pointer later
+
+    scheduled_response.dl_config = &dcireq.dl_config_req;
+    scheduled_response.ul_config = NULL;
+    scheduled_response.tx_request = NULL;
+    scheduled_response.module_id = UE->Mod_id;
+    scheduled_response.CC_id     = 0;
+    scheduled_response.frame = proc->frame_rx;
+    scheduled_response.slot  = proc->nr_tti_rx;
+    nr_ue_scheduled_response(&scheduled_response);
+
 #ifdef UE_SLOT_PARALLELISATION
     phy_procedures_slot_parallelization_nrUE_RX( UE, proc, 0, 0, 1, UE->mode, no_relay, NULL );
 #else
     uint64_t a=rdtsc();
-    phy_procedures_nrUE_RX( UE, proc, 0, 1, UE->mode, UE_mac->phy_config.config_req.pbch_config);
+    phy_procedures_nrUE_RX( UE, proc, 0, 1, UE->mode);
     LOG_D(PHY,"phy_procedures_nrUE_RX: slot:%d, time %lu\n", proc->nr_tti_rx, (rdtsc()-a)/3500);
     //printf(">>> nr_ue_pdcch_procedures ended\n");
 #endif
   }
 
+  
+  // no UL for now
+  /*
   if (UE->mac_enabled==1) {
     //  trigger L2 to run ue_scheduler thru IF module
     //  [TODO] mapping right after NR initial sync
@@ -395,6 +398,7 @@ void processSlotRX( PHY_VARS_NR_UE *UE, UE_nr_rxtx_proc_t *proc) {
       UE->if_inst->ul_indication(&UE->ul_indication);
     }
   }
+  */
 }
 
 /*!
diff --git a/maketags b/maketags
index eb7c474a38b3ce208a97cda0c6fdae41443af086..5c7232320a0abea10d81e4484aeffbdd2eccd623 100755
--- a/maketags
+++ b/maketags
@@ -1,4 +1,4 @@
 #!/bin/sh
 echo "building ctags for openair1 and openair2 ..."
-ctags -e -R  --exclude=openair1/DOCS/ --exclude=openair2/DOCS/ --exclude=openair1/SIMULATION/ --exclude=targets/DOCS/ --exclude=targets/PROJECTS/ openair1 openair2 openair3 targets cmake_targets common nfapi
+ctags -e -R  --exclude=openair1/DOCS/ --exclude=openair2/DOCS/ --exclude=openair1/SIMULATION/ --exclude=targets/DOCS/ --exclude=targets/PROJECTS/ openair1 openair2 openair3 targets cmake_targets common nfapi executables
 
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
index 73c5c3ef6f7060299c26f622f70cf5d9d7e47e40..b55bf05f1696a6bcd0287ec0fa5c337063e684fd 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
@@ -237,9 +237,9 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue,
   uint32_t Tbslbrm = 950984;
   uint16_t nb_rb = 30;
   double Coderate = 0.0;
-  nfapi_nr_config_request_t *cfg = &phy_vars_ue->nrUE_config;
-  uint8_t dmrs_type = cfg->pdsch_config.dmrs_type.value;
-  uint8_t nb_re_dmrs = (dmrs_type==NFAPI_NR_DMRS_TYPE1)?6:4;
+  //nfapi_nr_config_request_t *cfg = &phy_vars_ue->nrUE_config;
+  //uint8_t dmrs_type = cfg->pdsch_config.dmrs_type.value;
+  uint8_t nb_re_dmrs = 6; //(dmrs_type==NFAPI_NR_DMRS_TYPE1)?6:4;
   uint16_t length_dmrs = 1; //cfg->pdsch_config.dmrs_max_length.value;
 
   uint32_t i,j;
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c
index b56573f2b3c25ecece9968fac93cf053f502f0a7..641b27b081abd6a3e1b6fe478dfed7696e81b267 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c
@@ -566,8 +566,8 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue,
   }
 
   uint32_t payload = 0;
-  uint8_t xtra_byte = 0;
-  xtra_byte = (out>>24)&0xff;
+  //uint8_t xtra_byte = 0;
+  nr_ue_pbch_vars->xtra_byte = (out>>24)&0xff;
 
   for (int i=0; i<NR_POLAR_PBCH_PAYLOAD_BITS; i++)
     payload |= ((out>>i)&1)<<(NR_POLAR_PBCH_PAYLOAD_BITS-i-1);
@@ -575,18 +575,18 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue,
   for (int i=0; i<3; i++)
     decoded_output[i] = (uint8_t)((payload>>((3-i)<<3))&0xff);
 
-  n_hf = ((xtra_byte>>4)&0x01); // computing the half frame index from the extra byte
+  n_hf = ((nr_ue_pbch_vars->xtra_byte>>4)&0x01); // computing the half frame index from the extra byte
 
   ssb_index = i_ssb;  // ssb index corresponds to i_ssb for Lmax = 4,8
   if (Lmax == 64) {   // for Lmax = 64 ssb index 4th,5th and 6th bits are in extra byte
     for (int i=0; i<3; i++)
-      ssb_index += (((xtra_byte>>(7-i))&0x01)<<(3+i));
+      ssb_index += (((nr_ue_pbch_vars->xtra_byte>>(7-i))&0x01)<<(3+i));
   }
 
   ue->symbol_offset = nr_get_ssb_start_symbol(frame_parms, ssb_index, n_hf);
 
 #ifdef DEBUG_PBCH
-  printf("xtra_byte %x payload %x\n", xtra_byte, payload);
+  printf("xtra_byte %x payload %x\n", nr_ue_pbch_vars->xtra_byte, payload);
 
   for (int i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS>>3); i++) {
     //     printf("unscrambling pbch_a[%d] = %x \n", i,pbch_a[i]);
@@ -594,19 +594,25 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue,
   }
 #endif
 
-  ue->dl_indication.rx_ind = &ue->rx_ind; //  hang on rx_ind instance
-  ue->dl_indication.proc=proc;
-  //ue->rx_ind.sfn_slot = 0;  //should be set by higher-1-layer, i.e. clean_and_set_if_instance()
-  ue->rx_ind.rx_indication_body[0].pdu_type = FAPI_NR_RX_PDU_TYPE_MIB;
-  ue->rx_ind.rx_indication_body[0].mib_pdu.pdu = &decoded_output[0];
-  ue->rx_ind.rx_indication_body[0].mib_pdu.additional_bits = xtra_byte;
-  ue->rx_ind.rx_indication_body[0].mib_pdu.ssb_index = i_ssb;                //  confirm with TCL
-  ue->rx_ind.rx_indication_body[0].mib_pdu.ssb_length = Lmax;                //  confirm with TCL
-  ue->rx_ind.rx_indication_body[0].mib_pdu.cell_id = frame_parms->Nid_cell;  //  confirm with TCL
-  ue->rx_ind.number_pdus = 1;
+  nr_downlink_indication_t dl_indication;
+  fapi_nr_rx_indication_t rx_ind;
+    
+  dl_indication.rx_ind = &rx_ind; //  hang on rx_ind instance
+  dl_indication.dci_ind = NULL; 
+  dl_indication.proc=proc;        // needed to signal back the frame number -> FIXME
+  dl_indication.module_id=0;
+  dl_indication.cc_id=proc->CC_id;
+
+  rx_ind.rx_indication_body[0].pdu_type = FAPI_NR_RX_PDU_TYPE_MIB;
+  rx_ind.rx_indication_body[0].mib_pdu.pdu = &decoded_output[0]; //not good as it is pointing to a memory that can change
+  rx_ind.rx_indication_body[0].mib_pdu.additional_bits = nr_ue_pbch_vars->xtra_byte;
+  rx_ind.rx_indication_body[0].mib_pdu.ssb_index = i_ssb;                //  confirm with TCL
+  rx_ind.rx_indication_body[0].mib_pdu.ssb_length = Lmax;                //  confirm with TCL
+  rx_ind.rx_indication_body[0].mib_pdu.cell_id = frame_parms->Nid_cell;  //  confirm with TCL
+  rx_ind.number_pdus = 1;
 
   if (ue->if_inst && ue->if_inst->dl_indication)
-    ue->if_inst->dl_indication(&ue->dl_indication);
+    ue->if_inst->dl_indication(&dl_indication);
 
   return 0;
 }
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index 25b395bdf7a663bd42f319a756611a7f3bdc7eda..7b161ac23d5a862fd1e2d22c889e058b34ead8c3 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -50,15 +50,12 @@ int generate_ue_ulsch_params(PHY_VARS_NR_UE *UE,
                              unsigned char harq_pid){
 
   int N_PRB_oh, N_RE_prime, cwd_idx, length_dmrs, Nid_cell;
-  int nb_rb, Nsymb_pusch, first_rb, nb_codewords;
+  int nb_rb, Nsymb_pusch, first_rb, nb_codewords,mcs,rvidx;
   uint16_t n_rnti;
 
-  fapi_nr_dci_pdu_rel15_t *ul_dci_pdu;
   NR_UE_ULSCH_t *ulsch_ue;
   NR_UL_UE_HARQ_t *harq_process_ul_ue;
 
-  ul_dci_pdu = &UE->dci_ind.dci_list[0].dci;
-
   //--------------------------Temporary configuration-----------------------------//
   length_dmrs = 1;
   n_rnti = 0x1234;
@@ -66,7 +63,9 @@ int generate_ue_ulsch_params(PHY_VARS_NR_UE *UE,
   nb_rb = 50;
   first_rb = 30;
   Nsymb_pusch = 12;
-  nb_codewords = (ul_dci_pdu->precod_nbr_layers>4)?2:1;
+  nb_codewords = 1;
+  mcs = 9;
+  rvidx = 0;
   //------------------------------------------------------------------------------//
 
   for (cwd_idx = 0; cwd_idx < nb_codewords; cwd_idx++) {
@@ -87,19 +86,19 @@ int generate_ue_ulsch_params(PHY_VARS_NR_UE *UE,
 
     if (harq_process_ul_ue) {
 
-      harq_process_ul_ue->mcs                = ul_dci_pdu->mcs;
-      harq_process_ul_ue->Nl                 = ul_dci_pdu->precod_nbr_layers;
+      harq_process_ul_ue->mcs                = mcs;
+      harq_process_ul_ue->Nl                 = nb_codewords;
       harq_process_ul_ue->nb_rb              = nb_rb;
       harq_process_ul_ue->first_rb           = first_rb;
       harq_process_ul_ue->number_of_symbols  = Nsymb_pusch;
       harq_process_ul_ue->num_of_mod_symbols = N_RE_prime*nb_rb*nb_codewords;
-      harq_process_ul_ue->rvidx              = ul_dci_pdu->rv;
-      harq_process_ul_ue->TBS                = nr_compute_tbs(ul_dci_pdu->mcs,
+      harq_process_ul_ue->rvidx              = rvidx;
+      harq_process_ul_ue->TBS                = nr_compute_tbs(harq_process_ul_ue->mcs,
                                                               nb_rb,
                                                               Nsymb_pusch,
                                                               ulsch_ue->nb_re_dmrs,
                                                               length_dmrs,
-                                                              ul_dci_pdu->precod_nbr_layers);
+                                                              harq_process_ul_ue->Nl);
 
     }
 
diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h
index dceeaa79ceb4c80a27ee3cfc01a321c1d2bc7297..05ac832f8e8c5831a298b8d6e25e79b0a5ae472a 100644
--- a/openair1/PHY/defs_nr_UE.h
+++ b/openair1/PHY/defs_nr_UE.h
@@ -822,6 +822,8 @@ typedef struct {
   /// \brief Pointer to PBCH decoded output.
   /// - first index: ? [0..63] (hard coded)
   uint8_t *decoded_output;
+  /// \brief PBCH additional bits
+  uint8_t xtra_byte;
   /// \brief Total number of PDU errors.
   uint32_t pdu_errors;
   /// \brief Total number of PDU errors 128 frames ago.
@@ -923,18 +925,22 @@ typedef struct {
   NR_UE_COMMON    common_vars;
 
   nr_ue_if_module_t *if_inst;
-  nfapi_nr_config_request_t  nrUE_config;
 
-  nr_downlink_indication_t dl_indication;
-  nr_uplink_indication_t ul_indication;
+  //nfapi_nr_config_request_t  nrUE_config; <-- don't use config type for gNB!!!
+  fapi_nr_config_request_t nrUE_config;
+
+  // the following structures are not part of PHY_vars_UE anymore as it is not thread safe. They are now on the stack of the functions that actually need them
+  
+  //nr_downlink_indication_t dl_indication;
+  //nr_uplink_indication_t ul_indication;
   /// UE FAPI DCI request
-  nr_dcireq_t dcireq;
+  //nr_dcireq_t dcireq;
 
   // pointers to the next 2 strcutres are also included in dl_indictation
   /// UE FAPI indication for DLSCH reception
-  fapi_nr_rx_indication_t rx_ind;
+  //fapi_nr_rx_indication_t rx_ind;
   /// UE FAPI indication for DCI reception
-  fapi_nr_dci_indication_t dci_ind;
+  //fapi_nr_dci_indication_t dci_ind;
 
   // point to the current rxTx thread index
   uint8_t current_thread_id[40];
diff --git a/openair1/SCHED_NR_UE/defs.h b/openair1/SCHED_NR_UE/defs.h
index 28bb2c506457cbea281d7a66dc66ec02f36da3fd..79ce987466d0093c2770b783b4b06e4bad5eb3d6 100644
--- a/openair1/SCHED_NR_UE/defs.h
+++ b/openair1/SCHED_NR_UE/defs.h
@@ -123,7 +123,7 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t e
   @param r_type indicates the relaying operation: 0: no_relaying, 1: unicast relaying type 1, 2: unicast relaying type 2, 3: multicast relaying
   @param phy_vars_rn pointer to RN variables
 */
-int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t do_pdcch_flag,runmode_t mode,fapi_nr_pbch_config_t pbch_config);
+int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t do_pdcch_flag,runmode_t mode);
 int phy_procedures_slot_parallelization_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t abstraction_flag,uint8_t do_pdcch_flag,runmode_t mode,relaying_type_t r_type);
 
 
diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c
index b1d065ca77e94c55dd41b07ffd7227537ad6c90e..6802b77d8c639f8e1162bbe70bd034a7d80270de 100644
--- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c
+++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c
@@ -48,10 +48,10 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response)
   uint8_t cc_id = scheduled_response->CC_id;
   uint32_t i;
   int slot = scheduled_response->slot;
-  uint8_t thread_id = PHY_vars_UE_g[module_id][cc_id]->current_thread_id[slot];
 
   if(scheduled_response != NULL){
     // Note: we have to handle the thread IDs for this. To be revisited completely.
+    uint8_t thread_id = PHY_vars_UE_g[module_id][cc_id]->current_thread_id[slot];
     NR_UE_PDCCH *pdcch_vars2 = PHY_vars_UE_g[module_id][cc_id]->pdcch_vars[thread_id][0];
     NR_UE_DLSCH_t *dlsch0 = PHY_vars_UE_g[module_id][cc_id]->dlsch[thread_id][0][0];
     NR_UE_ULSCH_t *ulsch0 = PHY_vars_UE_g[module_id][cc_id]->ulsch[thread_id][0][0];
@@ -146,6 +146,7 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response)
 	  ulsch0->harq_processes[current_harq_pid]->mcs = pusch_config_pdu->mcs;
 	  ulsch0->harq_processes[current_harq_pid]->DCINdi = pusch_config_pdu->ndi;
 	  ulsch0->harq_processes[current_harq_pid]->rvidx = pusch_config_pdu->rv;
+	  ulsch0->harq_processes[current_harq_pid]->Nl = pusch_config_pdu->n_layers;
 	  ulsch0->f_pusch = pusch_config_pdu->absolute_delta_PUSCH;
 	}
 	if(ul_config->ul_config_list[i].pdu_type == FAPI_NR_UL_CONFIG_TYPE_PUCCH){
@@ -212,6 +213,8 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response)
 
 int8_t nr_ue_phy_config_request(nr_phy_config_t *phy_config){
 
+  fapi_nr_config_request_t nrUE_config = PHY_vars_UE_g[phy_config->Mod_id][phy_config->CC_id]->nrUE_config;
+  
   if(phy_config != NULL){
     if(phy_config->config_req.config_mask & FAPI_NR_CONFIG_REQUEST_MASK_PBCH){
       LOG_I(MAC,"[L1][IF module][PHY CONFIG]\n");
@@ -226,6 +229,8 @@ int8_t nr_ue_phy_config_request(nr_phy_config_t *phy_config){
       LOG_I(MAC,"half frame bit:              %d\n", phy_config->config_req.pbch_config.half_frame_bit);
       LOG_I(MAC,"-------------------------------\n");
 
+      memcpy(&nrUE_config.pbch_config,&phy_config->config_req.pbch_config,sizeof(fapi_nr_pbch_config_t));
+      
     }
         
     if(phy_config->config_req.config_mask & FAPI_NR_CONFIG_REQUEST_MASK_DL_BWP_COMMON){
diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
index 08966caab3b097654d67a70b55b788c95a067b2e..d6b947264dd2c0542c45e5cde4c3cae781abddce 100644
--- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
+++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
@@ -2464,11 +2464,11 @@ void ue_pucch_procedures(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB_
 
 
 void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue,
-                            UE_nr_rxtx_proc_t *proc,
-                            uint8_t gNB_id,
-                            uint8_t thread_id)
+		                    UE_nr_rxtx_proc_t *proc,
+							uint8_t gNB_id,
+							uint8_t thread_id)
 {
-  fapi_nr_dci_pdu_rel15_t *ul_dci_pdu;
+  NR_DL_FRAME_PARMS *frame_parms=&ue->frame_parms;
   NR_UE_ULSCH_t *ulsch_ue;
   NR_UL_UE_HARQ_t *harq_process_ul_ue;
   //int32_t ulsch_start=0;
@@ -2484,7 +2484,6 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue,
   start_meas(&ue->phy_proc_tx);
 #endif
 
-  ul_dci_pdu = &ue->dci_ind.dci_list[0].dci;
 
   harq_pid = 0; //temporary implementation
 
@@ -2496,7 +2495,7 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue,
   ulsch_ue = ue->ulsch[thread_id][gNB_id][0]; // cwd_index = 0
   harq_process_ul_ue = ulsch_ue->harq_processes[harq_pid];
 
-  TBS = nr_compute_tbs(ul_dci_pdu->mcs, harq_process_ul_ue->nb_rb, ulsch_ue->Nsymb_pusch, ulsch_ue->nb_re_dmrs, ulsch_ue->length_dmrs, ul_dci_pdu->precod_nbr_layers);
+  TBS = nr_compute_tbs( harq_process_ul_ue->mcs, harq_process_ul_ue->nb_rb, ulsch_ue->Nsymb_pusch, ulsch_ue->nb_re_dmrs, ulsch_ue->length_dmrs, harq_process_ul_ue->Nl);
 
 //-----------------------------------------------------//
   // to be removed later when MAC is ready
@@ -2525,7 +2524,7 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue,
 
   nr_ue_pusch_common_procedures(ue,
                                 slot_tx,
-                                ul_dci_pdu->precod_nbr_layers,
+                                harq_process_ul_ue->Nl,
                                 &ue->frame_parms);
 
 
@@ -2738,7 +2737,7 @@ void nr_ue_pbch_procedures(uint8_t eNB_id,
 		   ue->pbch_vars[eNB_id],
 		   &ue->frame_parms,
 		   eNB_id,
-		   ue->rx_ind.rx_indication_body[0].mib_pdu.ssb_index,
+		   ue->nrUE_config.pbch_config.ssb_index,
 		   SISO,
 		   ue->high_speed_flag);
 
@@ -2869,6 +2868,10 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,
 	 nr_tti_rx,nb_searchspace_total);
   #endif
 
+  //FK: we define dci_ind and dl_indication as local variables, this way the call to the mac should be thread safe
+  fapi_nr_dci_indication_t dci_ind;
+  nr_downlink_indication_t dl_indication;
+  
   // p in TS 38.212 Subclause 10.1, for each active BWP the UE can deal with 3 different CORESETs (including coresetId 0 for common search space)
   //int nb_coreset_total = NR_NBR_CORESET_ACT_BWP;
   unsigned int dci_cnt=0;
@@ -3061,7 +3064,7 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,
     //emos_dump_UE.dci_cnt[nr_tti_rx] = dci_cnt;
 #endif
 
-    ue->dci_ind.number_of_dcis = dci_cnt;
+    dci_ind.number_of_dcis = dci_cnt;
 
     for (int i=0; i<dci_cnt; i++) {
       /*
@@ -3101,12 +3104,12 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,
 	
 	LOG_D(PHY,"<-NR_PDCCH_PHY_PROCEDURES_UE (nr_ue_pdcch_procedures)-> dci_format=%d, rnti=%d, dci_length=%d, dci_pdu[0]=0x%lx, dci_pdu[1]=0x%lx\n",dci_alloc_rx[i].format,dci_alloc_rx[i].rnti,dci_alloc_rx[i].dci_length,dci_alloc_rx[i].dci_pdu[0],dci_alloc_rx[i].dci_pdu[1]);
 	
-	memset(&ue->dci_ind.dci_list[i].dci,0,sizeof(fapi_nr_dci_pdu_rel15_t));
+	memset(&dci_ind.dci_list[i].dci,0,sizeof(fapi_nr_dci_pdu_rel15_t));
 	
-	ue->dci_ind.dci_list[i].rnti = dci_alloc_rx[i].rnti;
-	ue->dci_ind.dci_list[i].dci_format = dci_alloc_rx[i].format;
-	ue->dci_ind.dci_list[i].n_CCE = dci_alloc_rx[i].firstCCE;
-	ue->dci_ind.dci_list[i].N_CCE = (int)dci_alloc_rx[i].L;
+	dci_ind.dci_list[i].rnti = dci_alloc_rx[i].rnti;
+	dci_ind.dci_list[i].dci_format = dci_alloc_rx[i].format;
+	dci_ind.dci_list[i].n_CCE = dci_alloc_rx[i].firstCCE;
+	dci_ind.dci_list[i].N_CCE = (int)dci_alloc_rx[i].L;
 	
 	status = nr_extract_dci_info(ue,
 				     eNB_id,
@@ -3114,7 +3117,7 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,
 				     dci_alloc_rx[i].dci_length,
 				     dci_alloc_rx[i].rnti,
 				     dci_alloc_rx[i].dci_pdu,
-				     &ue->dci_ind.dci_list[i].dci,
+				     &dci_ind.dci_list[i].dci,
 				     dci_fields_sizes_cnt[i],
 				     dci_alloc_rx[i].format,
 				     nr_tti_rx,
@@ -3156,16 +3159,16 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,
       } // end for loop dci_cnt
 
     // fill dl_indication message
-    ue->dl_indication.module_id = ue->Mod_id;
-    ue->dl_indication.cc_id = ue->CC_id;
-    ue->dl_indication.gNB_index = eNB_id;
-    ue->dl_indication.frame = frame_rx;
-    ue->dl_indication.slot = nr_tti_rx;
-    ue->dl_indication.rx_ind = NULL; //no data, only dci for now
-    ue->dl_indication.dci_ind = &ue->dci_ind; 
+    dl_indication.module_id = ue->Mod_id;
+    dl_indication.cc_id = ue->CC_id;
+    dl_indication.gNB_index = eNB_id;
+    dl_indication.frame = frame_rx;
+    dl_indication.slot = nr_tti_rx;
+    dl_indication.rx_ind = NULL; //no data, only dci for now
+    dl_indication.dci_ind = &dci_ind; 
     
     //  send to mac
-    ue->if_inst->dl_indication(&ue->dl_indication);
+    ue->if_inst->dl_indication(&dl_indication);
 
 #if UE_TIMING_TRACE
   stop_meas(&ue->dlsch_rx_pdcch_stats);
@@ -3312,165 +3315,6 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,
 
 #endif
 
-#if 0
-
-void ue_pmch_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc,int eNB_id,int abstraction_flag) {
-
-  int nr_tti_rx = proc->nr_tti_rx;
-  int frame_rx = proc->frame_rx;
-  int pmch_mcs=-1;
-#if defined(Rel10) || defined(Rel14)
-  int CC_id = ue->CC_id;
-#endif
-  uint8_t sync_area=255;
-  uint8_t mcch_active;
-  int l;
-  int ret=0;
-
-  if (is_pmch_subframe(frame_rx,nr_tti_rx,&ue->frame_parms)) {
-    LOG_D(PHY,"ue calling pmch nr_tti_rx ..\n ");
-
-    LOG_D(PHY,"[UE %d] Frame %d, nr_tti_rx %d: Querying for PMCH demodulation\n",
-	  ue->Mod_id,(nr_tti_rx==9?-1:0)+frame_rx,nr_tti_rx);
-#if defined(Rel10) || defined(Rel14)
-    /*pmch_mcs = mac_xface->ue_query_mch(ue->Mod_id,
-      CC_id,
-      frame_rx,
-      nr_tti_rx,
-      eNB_id,
-      &sync_area,
-      &mcch_active);*/
-
-#else
-    pmch_mcs=-1;
-#endif
-
-    if (pmch_mcs>=0) {
-      LOG_D(PHY,"[UE %d] Frame %d, nr_tti_rx %d: Programming PMCH demodulation for mcs %d\n",ue->Mod_id,frame_rx,nr_tti_rx,pmch_mcs);
-      fill_UE_dlsch_MCH(ue,pmch_mcs,1,0,0);
-
-      if (abstraction_flag == 0 ) {
-	for (l=2; l<12; l++) {
-
-	  slot_fep_mbsfn(ue,
-			 l,
-			 nr_tti_rx,
-			 0,0);//ue->rx_offset,0);
-	}
-
-	for (l=2; l<12; l++) {
-	  rx_pmch(ue,
-		  0,
-		  nr_tti_rx,
-		  l);
-	}
-
-
-	ue->dlsch_MCH[0]->harq_processes[0]->G = get_G(&ue->frame_parms,
-						       ue->dlsch_MCH[0]->harq_processes[0]->nb_rb,
-						       ue->dlsch_MCH[0]->harq_processes[0]->rb_alloc_even,
-						       ue->dlsch_MCH[0]->harq_processes[0]->Qm,
-						       1,
-						       2,
-						       frame_rx,
-						       nr_tti_rx,
-						       0);
-
-	dlsch_unscrambling(&ue->frame_parms,1,ue->dlsch_MCH[0],
-			   ue->dlsch_MCH[0]->harq_processes[0]->G,
-			   ue->pdsch_vars_MCH[0]->llr[0],0,nr_tti_rx<<1);
-
-#ifdef UE_DLSCH_PARALLELISATION
-	ret = dlsch_decoding_mthread(ue,proc, eNB_id,
-				     ue->pdsch_vars_MCH[0]->llr[0],
-				     &ue->frame_parms,
-				     ue->dlsch_MCH[0],
-				     ue->dlsch_MCH[0]->harq_processes[0],
-				     frame_rx,
-				     nr_tti_rx,
-				     0,
-				     0,1);
-#else
-	ret = dlsch_decoding(ue,
-			     ue->pdsch_vars_MCH[0]->llr[0],
-			     &ue->frame_parms,
-			     ue->dlsch_MCH[0],
-			     ue->dlsch_MCH[0]->harq_processes[0],
-			     frame_rx,
-			     nr_tti_rx,
-			     0,
-			     0,1);
-	printf("start pmch dlsch decoding\n");
-#endif
-      } else { // abstraction
-#ifdef PHY_ABSTRACTION
-	ret = dlsch_decoding_emul(ue,
-				  nr_tti_rx,
-				  5, // PMCH
-				  eNB_id);
-#endif
-      }
-
-      if (mcch_active == 1)
-	ue->dlsch_mcch_trials[sync_area][0]++;
-      else
-	ue->dlsch_mtch_trials[sync_area][0]++;
-
-      if (ret == (1+ue->dlsch_MCH[0]->max_turbo_iterations)) {
-	if (mcch_active == 1)
-	  ue->dlsch_mcch_errors[sync_area][0]++;
-	else
-	  ue->dlsch_mtch_errors[sync_area][0]++;
-
-	LOG_D(PHY,"[UE %d] Frame %d, nr_tti_rx %d: PMCH in error (%d,%d), not passing to L2 (TBS %d, iter %d,G %d)\n",
-	      ue->Mod_id,
-              frame_rx,nr_tti_rx,
-	      ue->dlsch_mcch_errors[sync_area][0],
-	      ue->dlsch_mtch_errors[sync_area][0],
-	      ue->dlsch_MCH[0]->harq_processes[0]->TBS>>3,
-	      ue->dlsch_MCH[0]->max_turbo_iterations,
-	      ue->dlsch_MCH[0]->harq_processes[0]->G);
-	dump_mch(ue,0,ue->dlsch_MCH[0]->harq_processes[0]->G,nr_tti_rx);
-#ifdef DEBUG_DLSCH
-
-	for (int i=0; i<ue->dlsch_MCH[0]->harq_processes[0]->TBS>>3; i++) {
-	  LOG_T(PHY,"%02x.",ue->dlsch_MCH[0]->harq_processes[0]->c[0][i]);
-	}
-
-	LOG_T(PHY,"\n");
-#endif
-
-	if (nr_tti_rx==9)
-	  //mac_xface->macphy_exit("Why are we exiting here?");
-	  } else { // decoding successful
-#if defined(Rel10) || defined(Rel14)
-
-	if (mcch_active == 1) {
-	  /*mac_xface->ue_send_mch_sdu(ue->Mod_id,
-	    CC_id,
-	    frame_rx,
-	    ue->dlsch_MCH[0]->harq_processes[0]->b,
-	    ue->dlsch_MCH[0]->harq_processes[0]->TBS>>3,
-	    eNB_id,// not relevant in eMBMS context
-	    sync_area);*/
-	  ue->dlsch_mcch_received[sync_area][0]++;
-
-
-	  if (ue->dlsch_mch_received_sf[nr_tti_rx%5][0] == 1 ) {
-	    ue->dlsch_mch_received_sf[nr_tti_rx%5][0]=0;
-	  } else {
-	    ue->dlsch_mch_received[0]+=1;
-	    ue->dlsch_mch_received_sf[nr_tti_rx][0]=1;
-	  }
-
-
-	}
-#endif // Rel10 || Rel14
-      } // decoding sucessful
-    } // pmch_mcs>=0
-  } // is_pmch_subframe=true
-}
-#endif
 
 void copy_harq_proc_struct(NR_DL_UE_HARQ_t *harq_processes_dest, NR_DL_UE_HARQ_t *current_harq_processes)
 {
@@ -3701,9 +3545,9 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
   NR_UE_PDSCH *pdsch_vars;
   uint8_t is_cw0_active = 0;
   uint8_t is_cw1_active = 0;
-  nfapi_nr_config_request_t *cfg = &ue->nrUE_config;
-  uint8_t dmrs_type = cfg->pdsch_config.dmrs_type.value;
-  uint8_t nb_re_dmrs = (dmrs_type==NFAPI_NR_DMRS_TYPE1)?6:4;
+  //nfapi_nr_config_request_t *cfg = &ue->nrUE_config;
+  //uint8_t dmrs_type = cfg->pdsch_config.dmrs_type.value;
+  uint8_t nb_re_dmrs = 6; //(dmrs_type==NFAPI_NR_DMRS_TYPE1)?6:4;
   uint16_t length_dmrs = 1; //cfg->pdsch_config.dmrs_max_length.value;
   uint16_t nb_symb_sch = 9;
 
@@ -4242,20 +4086,20 @@ void *UE_thread_slot1_dl_processing(void *arg) {
 #endif
 
 
-int is_pbch_in_slot(fapi_nr_pbch_config_t pbch_config, int frame, int slot, int periodicity, uint16_t slots_per_frame)  {
+int is_pbch_in_slot(fapi_nr_pbch_config_t *pbch_config, int frame, int slot, int periodicity, uint16_t slots_per_frame)  {
 
-  int ssb_slot_decoded = (pbch_config.ssb_index)/2;
+  int ssb_slot_decoded = (pbch_config->ssb_index)/2;
 
   if (periodicity == 5) {  
     // check for pbch in corresponding slot each half frame
-    if (pbch_config.half_frame_bit)
+    if (pbch_config->half_frame_bit)
       return(slot == ssb_slot_decoded || slot == ssb_slot_decoded - slots_per_frame/2);
     else
       return(slot == ssb_slot_decoded || slot == ssb_slot_decoded + slots_per_frame/2);
   }
   else {
     // if the current frame is supposed to contain ssb
-    if (!((frame-(pbch_config.system_frame_number))%(periodicity/10)))
+    if (!((frame-(pbch_config->system_frame_number))%(periodicity/10)))
       return(slot == ssb_slot_decoded);
     else
       return 0;
@@ -4267,8 +4111,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
 		                   UE_nr_rxtx_proc_t *proc,
 						   uint8_t eNB_id,
 						   uint8_t do_pdcch_flag,
-						   runmode_t mode,
-						   fapi_nr_pbch_config_t pbch_config)
+						   runmode_t mode)
 {
   int frame_rx = proc->frame_rx;
   int nr_tti_rx = proc->nr_tti_rx;
@@ -4281,6 +4124,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
   uint8_t nb_symb_pdcch = pdcch_vars->coreset[0].duration;
   uint8_t ssb_periodicity = 10;// ue->ssb_periodicity; // initialized to 5ms in nr_init_ue for scenarios where UE is not configured (otherwise acquired by cell configuration from gNB or LTE)
   uint8_t dci_cnt = 0;
+  fapi_nr_pbch_config_t *pbch_config = &ue->nrUE_config.pbch_config;
   
   LOG_D(PHY," ****** start RX-Chain for Frame.Slot %d.%d ******  \n", frame_rx%1024, nr_tti_rx);
 
@@ -4462,7 +4306,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
 #if UE_TIMING_TRACE
   	start_meas(&ue->dlsch_channel_estimation_stats);
 #endif
-   	nr_pbch_channel_estimation(ue,0,nr_tti_rx,(ue->symbol_offset+i)%(ue->frame_parms.symbols_per_slot),i-1,(pbch_config.ssb_index)&7,pbch_config.half_frame_bit);
+   	nr_pbch_channel_estimation(ue,0,nr_tti_rx,(ue->symbol_offset+i)%(ue->frame_parms.symbols_per_slot),i-1,(pbch_config->ssb_index)&7,pbch_config->half_frame_bit);
 #if UE_TIMING_TRACE
   	stop_meas(&ue->dlsch_channel_estimation_stats);
 #endif
@@ -4663,9 +4507,9 @@ return (0);
 }
 
 
-
-
-uint8_t is_cqi_TXOp(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t gNB_id)
+uint8_t is_cqi_TXOp(PHY_VARS_NR_UE *ue,
+		            UE_nr_rxtx_proc_t *proc,
+					uint8_t gNB_id)
 {
   int subframe = proc->subframe_tx;
   int frame    = proc->frame_tx;
@@ -4685,10 +4529,10 @@ uint8_t is_cqi_TXOp(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t gNB_id)
 }
 
 
-uint8_t is_ri_TXOp(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t gNB_id)
+uint8_t is_ri_TXOp(PHY_VARS_NR_UE *ue,
+		           UE_nr_rxtx_proc_t *proc,
+				   uint8_t gNB_id)
 {
-
-
   int subframe = proc->subframe_tx;
   int frame    = proc->frame_tx;
   CQI_REPORTPERIODIC *cqirep = &ue->cqi_report_config[gNB_id].CQI_ReportPeriodic;
diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c
index 34953f7626f3804ac9c0cb42687e055303994565..8f20998ffb3b97e9207426bcb2228c04613488ba 100644
--- a/openair1/SIMULATION/NR_PHY/dlsim.c
+++ b/openair1/SIMULATION/NR_PHY/dlsim.c
@@ -685,6 +685,8 @@ int main(int argc, char **argv)
   UE_mac->phy_config.config_req.pbch_config.ssb_index = 0;
   UE_mac->phy_config.config_req.pbch_config.half_frame_bit = 0;
 
+  nr_ue_phy_config_request(&UE_mac->phy_config);
+
   for (SNR=snr0; SNR<snr1; SNR+=.2) {
 
     n_errors = 0;
@@ -735,8 +737,7 @@ int main(int argc, char **argv)
 			       &UE_proc,
 			       0,
 			       do_pdcch_flag,
-			       normal_txrx,
-			       UE_mac->phy_config.config_req.pbch_config);
+			       normal_txrx);
 
 	if (n_trials==1) {
 	  LOG_M("rxsigF0.m","rxsF0", UE->common_vars.common_vars_rx_data_per_thread[0].rxdataF[0],slot_length_complex_samples_no_prefix,1,1);
@@ -744,7 +745,7 @@ int main(int argc, char **argv)
 	    LOG_M("rxsigF1.m","rxsF1", UE->common_vars.common_vars_rx_data_per_thread[0].rxdataF[1],slot_length_complex_samples_no_prefix,1,1);
 	}
 
-	if (UE->dci_ind.number_of_dcis==0) n_errors++;
+	if (UE_mac->dl_config_request.number_pdus==0) n_errors++; //if (UE->dci_ind.number_of_dcis==0) n_errors++;
       }
     } //noise trials
 
diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c
index e1f6ce8f5c8cd01e496bc11d6d792732552f6731..57ce2dc0aac4006f53b2a1b58a49c33471b14a2c 100644
--- a/openair1/SIMULATION/NR_PHY/pbchsim.c
+++ b/openair1/SIMULATION/NR_PHY/pbchsim.c
@@ -640,10 +640,10 @@ int main(int argc, char **argv)
 	  uint8_t gNB_xtra_byte=0;
 	  for (int i=0; i<8; i++)
 	    gNB_xtra_byte |= ((gNB->pbch.pbch_a>>(31-i))&1)<<(7-i);
-	  
-	  payload_ret = (UE->rx_ind.rx_indication_body->mib_pdu.additional_bits == gNB_xtra_byte);
+
+	  payload_ret = (UE->pbch_vars[0]->xtra_byte == gNB_xtra_byte);
 	  for (i=0;i<3;i++){
-	    payload_ret += (UE->rx_ind.rx_indication_body->mib_pdu.pdu[i] == gNB->pbch_pdu[2-i]);
+	    payload_ret += (UE->pbch_vars[0]->decoded_output[i] == gNB->pbch_pdu[2-i]);
 	    //printf("pdu byte %d gNB: 0x%02x UE: 0x%02x\n",i,gNB->pbch_pdu[i], UE->rx_ind.rx_indication_body->mib_pdu.pdu[i]); 
 	  } 
 	  //printf("xtra byte gNB: 0x%02x UE: 0x%02x\n",gNB_xtra_byte, UE->rx_ind.rx_indication_body->mib_pdu.additional_bits);
@@ -659,7 +659,6 @@ int main(int argc, char **argv)
 
     if (((float)n_errors/(float)n_trials <= target_error_rate) && (n_errors_payload==0)) {
       printf("PBCH test OK\n");
-      printf("Synchronization obtained for i_ssb = %d\n",UE->rx_ind.rx_indication_body[0].mib_pdu.ssb_index);
       break;
     }
       
diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c
index e477f32d45a3aef4fd0a99f1ec92e6e4326a204c..51e03f1f53b087d19b2b6f1d7132d3c0326c8a99 100644
--- a/openair1/SIMULATION/NR_PHY/ulsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulsim.c
@@ -55,6 +55,7 @@
 #include "PHY/TOOLS/tools_defs.h"
 #include "PHY/NR_TRANSPORT/nr_sch_dmrs.h"
 #include "PHY/phy_vars.h"
+#include "SCHED_NR_UE/fapi_nr_ue_l1.h"
 
 //#include "PHY/MODULATION/modulation_common.h"
 //#include "common/config/config_load_configmodule.h"
@@ -170,6 +171,7 @@ int main(int argc, char **argv) {
   int start_symbol = NR_SYMBOLS_PER_SLOT - nb_symb_sch;
   uint16_t nb_rb = 50;
   uint8_t Imcs = 9;
+  uint8_t precod_nbr_layers = 1;
   int gNB_id = 0;
   int ap;
   int tx_offset;
@@ -182,7 +184,6 @@ int main(int argc, char **argv) {
   cpuf = get_cpu_freq_GHz();
 
 
-  fapi_nr_dci_pdu_rel15_t *ul_dci_pdu;
   UE_nr_rxtx_proc_t UE_proc;
 
 
@@ -444,11 +445,6 @@ int main(int argc, char **argv) {
     }
   }
 
-  ul_dci_pdu = &UE->dci_ind.dci_list[0].dci;
-
-  ul_dci_pdu->mcs = Imcs;
-  ul_dci_pdu->rv = 0;
-  ul_dci_pdu->precod_nbr_layers = 1;
 
   unsigned char harq_pid = 0;
   unsigned int TBS = 8424;
@@ -459,14 +455,14 @@ int main(int argc, char **argv) {
 
   mod_order      = nr_get_Qm(Imcs, 1);
   available_bits = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, mod_order, 1);
-  TBS            = nr_compute_tbs(Imcs, nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, ul_dci_pdu->precod_nbr_layers);
+  TBS            = nr_compute_tbs(Imcs, nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, precod_nbr_layers);
 
   NR_gNB_ULSCH_t *ulsch_gNB = gNB->ulsch[UE_id+1][0];
   nfapi_nr_ul_config_ulsch_pdu *rel15_ul = &ulsch_gNB->harq_processes[harq_pid]->ulsch_pdu;
   
   NR_UE_ULSCH_t **ulsch_ue = UE->ulsch[0][0];
 
-  // --------- setting rel15_ul parameters ----------
+  // --------- setting rel15_ul parameters for gNB --------
   rel15_ul->rnti                           = n_rnti;
   rel15_ul->ulsch_pdu_rel15.start_rb       = start_rb;
   rel15_ul->ulsch_pdu_rel15.number_rbs     = nb_rb;
@@ -477,9 +473,41 @@ int main(int argc, char **argv) {
   rel15_ul->ulsch_pdu_rel15.Qm             = mod_order;
   rel15_ul->ulsch_pdu_rel15.mcs            = Imcs;
   rel15_ul->ulsch_pdu_rel15.rv             = 0;
-  rel15_ul->ulsch_pdu_rel15.n_layers       = ul_dci_pdu->precod_nbr_layers;
+  rel15_ul->ulsch_pdu_rel15.ndi            = 0;
+  rel15_ul->ulsch_pdu_rel15.n_layers       = precod_nbr_layers;
   ///////////////////////////////////////////////////
 
+  nr_scheduled_response_t scheduled_response;
+  fapi_nr_ul_config_request_t ul_config;
+  //fapi_nr_tx_request_t tx_request;
+
+  scheduled_response.module_id = 0;
+  scheduled_response.CC_id = 0;
+  scheduled_response.frame = frame;
+  scheduled_response.slot = slot;
+  scheduled_response.dl_config = NULL;
+  scheduled_response.ul_config = &ul_config;
+  scheduled_response.dl_config = NULL;
+  
+
+  ul_config.sfn_slot = slot;
+  ul_config.number_pdus = 1;
+  ul_config.ul_config_list[0].pdu_type = FAPI_NR_UL_CONFIG_TYPE_PUSCH;
+  ul_config.ul_config_list[0].ulsch_config_pdu.rnti = n_rnti;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.number_rbs = nb_rb;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.start_rb = start_rb;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.number_symbols = nb_symb_sch;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.start_symbol = start_symbol;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.mcs = Imcs;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.ndi = 0;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.rv = 0;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.n_layers = precod_nbr_layers;
+  //there are plenty of other parameters that we don't seem to be using for now. e.g.
+  //ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.absolute_delta_PUSCH = 0; 
+
+  // set FAPI parameters for UE, put them in the scheduled response and call 
+  //nr_ue_scheduled_response(&scheduled_response);
+
   unsigned char *estimated_output_bit;
   unsigned char *test_input_bit;
   unsigned int errors_bit = 0;
diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c
index c9f393cf46fa2e8387e6d871983d9a28dfd0a29c..92464f4448949e66acd24cc01782f1058fac6627 100644
--- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c
+++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c
@@ -72,14 +72,15 @@ int handle_dci(module_id_t module_id, int cc_id, unsigned int gNB_index, fapi_nr
 //  L2 Abstraction Layer
 int8_t handle_dlsch (module_id_t module_id, int cc_id, uint8_t gNB_index, fapi_nr_dci_indication_t *dci_ind, uint8_t *pduP, uint32_t pdu_len){
 
-  //    return 0;
+  return 0;
+  /*
   return nr_ue_process_dlsch( module_id,
 			      cc_id,
 			      gNB_index,
 			      dci_ind,
 			      pduP,
 			      pdu_len);
-
+  */
 }
 
 int nr_ue_ul_indication(nr_uplink_indication_t *ul_info){
@@ -156,6 +157,9 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info){
 			      (dl_info->dci_ind->dci_list+i)->rnti, 
 			      (dl_info->dci_ind->dci_list+i)->dci_format)) << FAPI_NR_DCI_IND;
 
+      AssertFatal( nr_ue_if_module_inst[module_id] != NULL, "IF module is void!\n" );
+      nr_ue_if_module_inst[module_id]->scheduled_response(&mac->scheduled_response);
+
 
       /*switch((dl_info->dci_ind->dci_list+i)->dci_type){
 	case FAPI_NR_DCI_TYPE_0_0:
@@ -242,9 +246,6 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info){
   dl_info->rx_ind = NULL;
   dl_info->dci_ind = NULL;
 
-  AssertFatal( nr_ue_if_module_inst[module_id] != NULL, "IF module is void!\n" );
-  nr_ue_if_module_inst[module_id]->scheduled_response(&mac->scheduled_response);
-
   return 0;
 }
 
diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h
index c1c85227491927b665676af811dfb7ce16b82471..3f642cac4b39e8b02fd494151483b3a9d7e40deb 100755
--- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h
+++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h
@@ -65,6 +65,7 @@ typedef struct {
     frame_t frame;
     /// slot
     int slot;
+    /// proc is needed to signal back decoded frame number to PHY. However, this is not really FAPI procedure and should be done differently
     UE_nr_rxtx_proc_t * proc;
 
     /// NR UE FAPI-like P7 message, direction: L1 to L2
diff --git a/targets/ARCH/COMMON/common_lib.c b/targets/ARCH/COMMON/common_lib.c
index c6c349272e86d84f9fdf9dc668815320096bf98a..21b9964c9f8c1e9e19c2c9af7dcf35edba6daeda 100644
--- a/targets/ARCH/COMMON/common_lib.c
+++ b/targets/ARCH/COMMON/common_lib.c
@@ -135,7 +135,7 @@ int load_lib(openair0_device *device,
   return ret;
 }
 
-
+/*
 void uhd_set_thread_prio(void) {
   
   loader_shlibfunc_t shlib_fdesc[1];
@@ -146,15 +146,16 @@ void uhd_set_thread_prio(void) {
     libname="rfsimulator";
   else 
     libname=OAI_RF_LIBNAME;
-  shlib_fdesc[0].fname="uhd_set_thread_priority";
+  //shlib_fdesc[0].fname="uhd_set_thread_priority";
   ret=load_module_shlib(libname,shlib_fdesc,1,NULL);
   if (ret < 0) {
     LOG_E(HW,"Library %s couldn't be loaded\n",libname);
   } else {
-    (set_prio_func_t)shlib_fdesc[0].fptr();
+    //(set_prio_func_t)shlib_fdesc[0].fptr();
   }    
   //return ret;
 }
+*/
 
 int openair0_device_load(openair0_device *device,
 		                 openair0_config_t *openair0_cfg)
diff --git a/targets/ARCH/COMMON/common_lib.h b/targets/ARCH/COMMON/common_lib.h
index 3aa4f714acaab1173f950f38e309a58026bd5376..168a364b3242b4dfd2ac7e25fc1e73b0ab44f52d 100644
--- a/targets/ARCH/COMMON/common_lib.h
+++ b/targets/ARCH/COMMON/common_lib.h
@@ -454,7 +454,7 @@ int openair0_set_rx_frequencies(openair0_device *device, openair0_config_t *open
 
   void uhd_set_thread_prio(void);
   typedef void(*set_prio_func_t)(void);
-  set_prio_func_t uhd_set_thread_priority_fun;
+  //set_prio_func_t uhd_set_thread_priority_fun;
 
 #ifdef __cplusplus
 }
diff --git a/targets/ARCH/rfsimulator/simulator.c b/targets/ARCH/rfsimulator/simulator.c
index d5f77acc9186abbaa049d3b317200a9a2db5e1d2..42bf766bafa05006fbd836c749e8ab2547c8e56d 100644
--- a/targets/ARCH/rfsimulator/simulator.c
+++ b/targets/ARCH/rfsimulator/simulator.c
@@ -47,8 +47,8 @@ pthread_mutex_t Sockmutex;
 
 typedef struct buffer_s {
   int conn_sock;
-  bool alreadyRead;
-  uint64_t lastReceivedTS;
+  openair0_timestamp lastReceivedTS;
+  openair0_timestamp lastWroteTS;
   bool headerMode;
   samplesBlockHeader_t th;
   char *transferPtr;
@@ -60,7 +60,7 @@ typedef struct buffer_s {
 
 typedef struct {
   int listen_sock, epollfd;
-  uint64_t nextTimestamp;
+  openair0_timestamp nextTimestamp;
   uint64_t typeStamp;
   char *ip;
   int saveIQfile;
@@ -105,7 +105,9 @@ void rxAddInput( struct complex16 *input_sig, struct complex16 *after_channel_si
   // the parameter "-s" is declared as SNR, but the input power is not well defined
   // −132.24 dBm is a LTE subcarrier noise, that was used in origin code (15KHz BW thermal noise)
   const double rxGain= 132.24 - snr_dB;
-  const double noise_per_sample = sqrt(0.5*noise_figure_watt) * pow(10,rxGain/20);
+  // sqrt(4*noise_figure_watt) is the thermal noise factor (volts)
+  // fixme: the last constant is pure trial results to make decent noise
+  const double noise_per_sample = sqrt(4*noise_figure_watt) * pow(10,rxGain/20) *10;
   // Fixme: we don't fill the offset length samples at begining ?
   // anyway, in today code, channel_offset=0
   const int dd = abs(channelDesc->channel_offset);
@@ -133,11 +135,6 @@ void rxAddInput( struct complex16 *input_sig, struct complex16 *after_channel_si
     }
 
     out_ptr->r += round(rx_tmp.x*pathLossLinear + noise_per_sample*gaussdouble(0.0,1.0));
-    /*
-      printf("in: %d, out %d= %f*%f + %f*%f\n",
-      input_sig[((TS+i)*nbTx)%CirSize].r, out_ptr->r , rx_tmp.x,
-      pathLossLinear, noise_per_sample,gaussdouble(0.0,1.0));
-    */
     out_ptr->i += round(rx_tmp.y*pathLossLinear + noise_per_sample*gaussdouble(0.0,1.0));
     out_ptr++;
   }
@@ -156,8 +153,8 @@ void allocCirBuf(rfsimulator_state_t *bridge, int sock) {
   AssertFatal ( (ptr->circularBuf=(sample_t *) malloc(sampleToByte(CirSize,1))) != NULL, "");
   ptr->circularBufEnd=((char *)ptr->circularBuf)+sampleToByte(CirSize,1);
   ptr->conn_sock=sock;
-  ptr->alreadyRead=false;
   ptr->lastReceivedTS=0;
+  ptr->lastWroteTS=0;
   ptr->headerMode=true;
   ptr->transferPtr=(char *)&ptr->th;
   ptr->remainToTransfer=sizeof(samplesBlockHeader_t);
@@ -322,21 +319,22 @@ sin_addr:
 
   setblocking(sock, notBlocking);
   allocCirBuf(t, sock);
-  t->buf[sock].alreadyRead=true; // UE will start blocking on read
   return 0;
 }
 
-uint64_t lastW=-1;
 int rfsimulator_write(openair0_device *device, openair0_timestamp timestamp, void **samplesVoid, int nsamps, int nbAnt, int flags) {
   rfsimulator_state_t *t = device->priv;
   LOG_D(HW,"sending %d samples at time: %ld\n", nsamps, timestamp);
 
+
   for (int i=0; i<FD_SETSIZE; i++) {
-    buffer_t *ptr=&t->buf[i];
+    buffer_t *b=&t->buf[i];
 
-    if (ptr->conn_sock >= 0 ) {
+    if (b->conn_sock >= 0 ) {
+      if ( abs((double)b->lastWroteTS-timestamp) > (double)CirSize)
+	LOG_E(HW,"Tx/Rx shift too large Tx:%lu, Rx:%lu\n", b->lastWroteTS, b->lastReceivedTS);
       samplesBlockHeader_t header= {t->typeStamp, nsamps, nbAnt, timestamp};
-      fullwrite(ptr->conn_sock,&header, sizeof(header), t);
+      fullwrite(b->conn_sock,&header, sizeof(header), t);
       sample_t tmpSamples[nsamps][nbAnt];
 
       for(int a=0; a<nbAnt; a++) {
@@ -346,17 +344,17 @@ int rfsimulator_write(openair0_device *device, openair0_timestamp timestamp, voi
           tmpSamples[s][a]=in[s];
       }
 
-      if (ptr->conn_sock >= 0 )
-        fullwrite(ptr->conn_sock, (void *)tmpSamples, sampleToByte(nsamps,nbAnt), t);
+      if (b->conn_sock >= 0 ) {
+        fullwrite(b->conn_sock, (void *)tmpSamples, sampleToByte(nsamps,nbAnt), t);
+        b->lastWroteTS=timestamp+nsamps;
+      }
     }
   }
 
-  lastW=timestamp;
   LOG_D(HW,"sent %d samples at time: %ld->%ld, energy in first antenna: %d\n",
         nsamps, timestamp, timestamp+nsamps, signal_energy(samplesVoid[0], nsamps) );
   // Let's verify we don't have incoming data
   // This is mandatory when the opposite side don't transmit
-  // This is mandatory when the opposite side don't transmit
   flushInput(t, 0);
   pthread_mutex_unlock(&Sockmutex);
   return nsamps;
@@ -428,7 +426,6 @@ static bool flushInput(rfsimulator_state_t *t, int timeout) {
         AssertFatal( (t->typeStamp == UE_MAGICDL_FDD  && b->th.magic==ENB_MAGICDL_FDD) ||
                      (t->typeStamp == ENB_MAGICDL_FDD && b->th.magic==UE_MAGICDL_FDD), "Socket Error in protocol");
         b->headerMode=false;
-        b->alreadyRead=true;
 
         if ( b->lastReceivedTS != b->th.timestamp) {
           int nbAnt= b->th.nbAnt;
@@ -444,8 +441,8 @@ static bool flushInput(rfsimulator_state_t *t, int timeout) {
         }
 
         b->lastReceivedTS=b->th.timestamp;
-        AssertFatal(lastW == -1 || ( abs((double)lastW-b->lastReceivedTS) < (double)CirSize),
-                    "Tx/Rx shift too large Tx:%lu, Rx:%lu\n", lastW, b->lastReceivedTS);
+        AssertFatal(b->lastWroteTS == 0 || ( abs((double)b->lastWroteTS-b->lastReceivedTS) < (double)CirSize),
+                    "Tx/Rx shift too large Tx:%lu, Rx:%lu\n", b->lastWroteTS, b->lastReceivedTS);
         b->transferPtr=(char *)&b->circularBuf[b->lastReceivedTS%CirSize];
         b->remainToTransfer=sampleToByte(b->th.size, b->th.nbAnt);
       }
@@ -501,15 +498,33 @@ int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimestamp, vo
       return nsamps;
     }
   } else {
+    
     bool have_to_wait;
 
     do {
       have_to_wait=false;
 
       for ( int sock=0; sock<FD_SETSIZE; sock++) {
-        if ( t->buf[sock].circularBuf && t->buf[sock].alreadyRead )
-          if ( t->buf[sock].lastReceivedTS == 0 ||
-               (t->nextTimestamp+nsamps) > t->buf[sock].lastReceivedTS ) {
+	buffer_t *b=&t->buf[sock];
+        if ( b->circularBuf) {
+          LOG_D(HW,"sock: %d, lastWroteTS: %lu, lastRecvTS: %lu, TS must be avail: %lu\n",
+                sock, b->lastWroteTS,
+                b->lastReceivedTS,
+                t->nextTimestamp+nsamps);
+	  if (  b->lastReceivedTS > b->lastWroteTS ) {
+	    // The caller momdem (NB, UE, ...) must send Tx in advance, so we fill TX if Rx is in advance
+	    // This occurs for example when UE is in sync mode: it doesn't transmit
+	    // with USRP, it seems ok: if "tx stream" is off, we may consider it actually cuts the Tx power
+	    struct complex16 v={0};
+	    void *samplesVoid[b->th.nbAnt];
+	    for ( int i=0; i <b->th.nbAnt; i++)
+	      samplesVoid[i]=(void*)&v;
+	    rfsimulator_write(device, b->lastReceivedTS, samplesVoid, 1, b->th.nbAnt, 0);
+	  }
+	}
+
+        if ( b->circularBuf )
+          if ( t->nextTimestamp+nsamps > b->lastReceivedTS ) {
             have_to_wait=true;
             break;
           }
@@ -532,7 +547,7 @@ int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimestamp, vo
   for (int sock=0; sock<FD_SETSIZE; sock++) {
     buffer_t *ptr=&t->buf[sock];
 
-    if ( ptr->circularBuf && ptr->alreadyRead ) {
+    if ( ptr->circularBuf ) {
       bool reGenerateChannel=false;
 
       //fixme: when do we regenerate