diff --git a/openair1/PHY/NR_REFSIG/nr_gold.c b/openair1/PHY/NR_REFSIG/nr_gold.c
index f519a58da35dac0ac2920533276ddf9c12c2a7c6..bd2df98ed6b84a5742e61e5a951191076fc0a21a 100644
--- a/openair1/PHY/NR_REFSIG/nr_gold.c
+++ b/openair1/PHY/NR_REFSIG/nr_gold.c
@@ -81,7 +81,7 @@ void nr_init_pdsch_dmrs(PHY_VARS_gNB* gNB, uint32_t Nid)
 {
   
   uint32_t x1, x2;
-  uint8_t reset;
+  uint8_t reset, q;
   NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
   uint32_t ****pdsch_dmrs = gNB->nr_gold_pdsch_dmrs;
 
@@ -89,18 +89,17 @@ void nr_init_pdsch_dmrs(PHY_VARS_gNB* gNB, uint32_t Nid)
   uint8_t n_scid=0; // again works only for 1_0
   for (uint8_t slot=0; slot<fp->slots_per_frame; slot++) {
     for (uint8_t symb=0; symb<fp->symbols_per_slot; symb++) {
-      for (uint8_t q=0; q<NR_MAX_NB_CODEWORDS; q++) {
-
         reset = 1;
         x2 = ((1<<17) * (fp->symbols_per_slot*slot+symb+1) * ((N_n_scid[n_scid]<<1)+1) +((N_n_scid[n_scid]<<1)+n_scid));
         for (uint32_t n=0; n<NR_MAX_PDSCH_DMRS_INIT_LENGTH_DWORD; n++) {
-          pdsch_dmrs[slot][symb][q][n] = lte_gold_generic(&x1, &x2, reset);
+          pdsch_dmrs[slot][symb][0][n] = lte_gold_generic(&x1, &x2, reset);
           reset = 0;
-        }          
-      }
-    }  
-  }
+        }
 
+        for (q = 1; q < NR_MAX_NB_CODEWORDS; q++)
+          memcpy(pdsch_dmrs[slot][symb][q],pdsch_dmrs[slot][symb][0],sizeof(uint32_t)*NR_MAX_PDSCH_DMRS_INIT_LENGTH_DWORD);
+    }
+  }
 }
 
 void nr_init_pusch_dmrs(PHY_VARS_NR_UE* ue, uint16_t *N_n_scid, uint8_t n_scid)
@@ -115,19 +114,16 @@ void nr_init_pusch_dmrs(PHY_VARS_NR_UE* ue, uint16_t *N_n_scid, uint8_t n_scid)
 
     for (symb=0; symb<fp->symbols_per_slot; symb++) {
 
-      for (q=0; q<NR_MAX_NB_CODEWORDS; q++) {
-
-        reset = 1;
-        x2 = ((1<<17) * (fp->symbols_per_slot*slot+symb+1) * ((N_n_scid[n_scid]<<1)+1) +((N_n_scid[n_scid]<<1)+n_scid));
-
-        for (n=0; n<NR_MAX_PUSCH_DMRS_INIT_LENGTH_DWORD; n++) {
-
-          pusch_dmrs[slot][symb][q][n] = lte_gold_generic(&x1, &x2, reset);
-          reset = 0;
+      reset = 1;
+      x2 = ((1<<17) * (fp->symbols_per_slot*slot+symb+1) * ((N_n_scid[n_scid]<<1)+1) +((N_n_scid[n_scid]<<1)+n_scid));
 
-        }          
+      for (n=0; n<NR_MAX_PUSCH_DMRS_INIT_LENGTH_DWORD; n++) {
+        pusch_dmrs[slot][symb][0][n] = lte_gold_generic(&x1, &x2, reset);
+        reset = 0;
       }
-    }  
-  }
 
+      for (q = 1; q < NR_MAX_NB_CODEWORDS; q++)
+        memcpy(pusch_dmrs[slot][symb][q],pusch_dmrs[slot][symb][0],sizeof(uint32_t)*NR_MAX_PUSCH_DMRS_INIT_LENGTH_DWORD);
+    }
+  }
 }
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dci.c b/openair1/PHY/NR_TRANSPORT/nr_dci.c
index 2cea05e6b11cacdd309328ea2e31faa39ac95b5d..ab3cf4af9b04a60ec28602d1095e0e32a8f4a83c 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dci.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dci.c
@@ -32,6 +32,7 @@
 
 #include "nr_dci.h"
 #include "nr_dlsch.h"
+#include "nr_sch_dmrs.h"
 #include "PHY/MODULATION/nr_modulation.h"
 
 //#define DEBUG_PDCCH_DMRS
@@ -216,9 +217,9 @@ uint8_t nr_generate_dci_top(NR_gNB_PDCCH pdcch_vars,
 #endif
       }
 
-      nr_modulation(dmrs_seq, dmrs_length, 2, mod_dmrs[symb]); //Qm = 2 as DMRS is QPSK modulated
+      nr_modulation(dmrs_seq, dmrs_length, DMRS_MOD_ORDER, mod_dmrs[symb]); //Qm = 2 as DMRS is QPSK modulated
     } else
-      nr_modulation(gold_pdcch_dmrs[symb], dmrs_length, 2, mod_dmrs[symb]); //Qm = 2 as DMRS is QPSK modulated
+      nr_modulation(gold_pdcch_dmrs[symb], dmrs_length, DMRS_MOD_ORDER, mod_dmrs[symb]); //Qm = 2 as DMRS is QPSK modulated
 
 #ifdef DEBUG_PDCCH_DMRS
 
@@ -263,7 +264,7 @@ uint8_t nr_generate_dci_top(NR_gNB_PDCCH pdcch_vars,
 #endif
   /// QPSK modulation
   int16_t mod_dci[NR_MAX_DCI_SIZE>>1];
-  nr_modulation(scrambled_output, encoded_length, 2, mod_dci); //Qm = 2 as DMRS is QPSK modulated
+  nr_modulation(scrambled_output, encoded_length, DMRS_MOD_ORDER, mod_dci); //Qm = 2 as DMRS is QPSK modulated
 #ifdef DEBUG_DCI
 
   for (int i=0; i<encoded_length>>1; i++)
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch.c
index 51a3ffb5177cd637d59b483a994afd0cfb29ac5d..3316e507c69056973ade3f012dabdcba78615ca9 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch.c
@@ -173,7 +173,7 @@ for (int l=0; l<rel15->nb_layers; l++)
   uint8_t mapping_type = config->pdsch_config.mapping_type.value;
 
   l0 = get_l0(mapping_type, 2, 0);//config->pdsch_config.dmrs_typeA_position.value);
-  nr_modulation(pdsch_dmrs[l0][0], n_dmrs, 2, mod_dmrs); // currently only codeword 0 is modulated. Qm = 2 as DMRS is QPSK modulated
+  nr_modulation(pdsch_dmrs[l0][0], n_dmrs, DMRS_MOD_ORDER, mod_dmrs); // currently only codeword 0 is modulated. Qm = 2 as DMRS is QPSK modulated
 
 #ifdef DEBUG_DLSCH
 printf("DMRS modulation (single symbol %d, %d symbols, type %d):\n", l0, n_dmrs>>1, dmrs_type);
diff --git a/openair1/PHY/NR_TRANSPORT/nr_sch_dmrs.h b/openair1/PHY/NR_TRANSPORT/nr_sch_dmrs.h
index c6557530122a14103aa13a6835e1ff5caf77aaf6..ab8f21395e64a79b492f1add158e9d510957d451 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_sch_dmrs.h
+++ b/openair1/PHY/NR_TRANSPORT/nr_sch_dmrs.h
@@ -34,6 +34,7 @@
 
 #define NR_PDSCH_DMRS_ANTENNA_PORT0 1000
 #define NR_PDSCH_DMRS_NB_ANTENNA_PORTS 12
+#define DMRS_MOD_ORDER 2
 
 void get_l_prime(uint8_t *l_prime, uint8_t n_symbs);
 
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index 40eac485f3710ff0faa2851089254262f5aa9e45..49e8d9778ee50149abde1b430d95d5b6002ca7ba 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -43,7 +43,7 @@ void nr_pusch_codeword_scrambling(uint8_t *in,
                          uint32_t* out) {
 
   uint8_t reset, b_idx;
-  uint32_t x1, x2, s=0;
+  uint32_t x1, x2, s=0, temp_out;
 
   reset = 1;
   x2 = (n_RNTI<<15) + Nid;
@@ -58,8 +58,16 @@ void nr_pusch_codeword_scrambling(uint8_t *in,
     }
     if (in[i]==NR_PUSCH_x)
       *out ^= 1<<b_idx;
-    else if (in[i]==NR_PUSCH_y)
-      *out ^= (*out & (1<<b_idx-1))<<b_idx;
+    else if (in[i]==NR_PUSCH_y){
+      if (b_idx!=0)
+        *out ^= (*out & (1<<(b_idx-1)))<<1;
+      else{
+
+        temp_out = *(out-1);
+        *out ^= temp_out>>31;
+
+      }
+    }
     else
       *out ^= (((in[i])&1) ^ ((s>>b_idx)&1))<<b_idx;
     //printf("i %d b_idx %d in %d s 0x%08x out 0x%08x\n", i, b_idx, in[i], s, *out);
diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c
index 441ff4577c1bf9726f228a0a7a86f3a558f300eb..2f1e5b460c9a250073bfe411e6e6fe22a167b403 100644
--- a/openair1/SIMULATION/NR_PHY/ulsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulsim.c
@@ -46,6 +46,7 @@
 #include "PHY/NR_TRANSPORT/nr_transport.h"
 #include "PHY/NR_TRANSPORT/nr_dlsch.h"
 #include "PHY/NR_TRANSPORT/nr_ulsch.h"
+#include "PHY/NR_TRANSPORT/nr_sch_dmrs.h"
 #include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h"
 
 #include "SCHED_NR/sched_nr.h"
@@ -595,7 +596,7 @@ int main(int argc, char **argv) {
   mapping_type = UE->pusch_config.pusch_TimeDomainResourceAllocation[0]->mappingType;
 
   l0 = get_l0(mapping_type, 2, 1);
-  nr_modulation(pusch_dmrs[l0][0], n_dmrs, 2, mod_dmrs); // currently only codeword 0 is modulated. Qm = 2 as DMRS is QPSK modulated
+  nr_modulation(pusch_dmrs[l0][0], n_dmrs, DMRS_MOD_ORDER, mod_dmrs); // currently only codeword 0 is modulated. Qm = 2 as DMRS is QPSK modulated
 
 
   ///////////