#318: properly remove non-duplicate elements

Resolves #318.