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

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

        
        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)
        
