fix bug and remove duplicates