fix bug with repeated elements