Moved duplicated flag check to  function