Fix bug with repeated elements.