Update the code to avoid having duplicated rows