                         return nil
                     }
                     if let ground = replaced.ground {
-                        triples.append(ground)
+                        triples.insert(ground)
                     }
                 } catch {}
             }
         }
-        return triples
+        return Array(triples)
     }
     
     public func evaluate(query: Query, activeGraph: Term) throws -> QueryResult<[TermResult], [Triple]> {

        case .select(_):
            return QueryResult.bindings(query.projectedVariables, results)
        case .construct(let template):
            let t = triples(from: iter, with: template)
            return QueryResult.triples(t)
        default:
            throw QueryError.evaluationError("TODO: evaluate(query) not implemented for \(query.form)")

        return .variable(".v\(n)", binding: true)
    }
    
    private func triples<S : Sequence>(from results: S, with template: [TriplePattern]) -> [Triple] where S.Element == TermResult {
        var triples = Set<Triple>()
        for r in results {
            for tp in template {
                do {
