                     } catch {}
                 }
             }
-            return QueryResult.triples(Array(triples))
+            return (plan, QueryResult.triples(Array(triples)))
         case .describe(_):
             throw QueryPlanError.unimplemented("DESCRIBE")
         }

        case .ask:
            let i = seq.makeIterator()
            if let _ = i.next() {
                return QueryResult.boolean(true)
            } else {
                return QueryResult.boolean(false)
            }
        case .select(.star):
            return QueryResult.bindings(Array(q.inscope), seq)
        case .select(.variables(let vars)):
            return QueryResult.bindings(vars, seq)
        case .construct(let template):
            var triples = Set<Triple>()
            for r in seq {

        
        return AnyIterator(seq.makeIterator())
    }

    public func evaluate(query: Query, activeGraph graph: Term? = nil) throws -> QueryResult<AnySequence<SPARQLResultSolution<Term>>, [Triple]> {
        let (_, results) = try planAndEvaluate(query: query, activeGraph: graph)
        return results
    }
    
    public func planAndEvaluate(query: Query, activeGraph graph: Term? = nil) throws -> (QueryPlan, QueryResult<AnySequence<SPARQLResultSolution<Term>>, [Triple]>) {
        let rewriter = SPARQLQueryRewriter()
        let q = try rewriter.simplify(query: query)
        
