             graph = Term(value: iri, type: .iri)
         }
         guard let qfile = args.next() else { fatalError("No query file given") }
-        let url = URL(fileURLWithPath: qfile)
-        let sparql = try Data(contentsOf: url)
+        let sparql = try data(fromFileOrString: qfile)
         guard var p = SPARQLParser(data: sparql) else { fatalError("Failed to construct SPARQL parser") }
         do {
             let q = try p.parseQuery()

if let op = args.next() {
    try setup(database, startTime: startSecond)
    if op == "load" {
        var graph: Term? = nil
        if let next = args.peek(), next == "-g" {
            _ = args.next()
            guard let iri = args.next() else { fatalError("No IRI value given after -g") }
            graph = Term(value: iri, type: .iri)
        }

        count = try parse(database, files: args.elements(), startTime: startSecond, graph: graph)
    } else if op == "sort" {
        var graph: Term? = nil
        if let next = args.peek(), next == "-g" {
            _ = args.next()
            guard let iri = args.next() else { fatalError("No IRI value given after -g") }
            graph = Term(value: iri, type: .iri)
        }
        
        let (c, terms) = try sortParse(files: args.elements(), graph: graph)
        for i in terms.keys.sorted() {
            if let term = terms[i] {
                print("\(i)\t\(term)")
            }
        }
        count = c
    } else if op == "terms" {
        count = try printTerms(from: database)
    } else if op == "graphs" {

    } else if op == "indexes" {
        count = try printIndexes(from: database)
    } else if op == "parse", let qfile = args.next() {
        do {
            let sparql = try data(fromFileOrString: qfile)
            guard var p = SPARQLParser(data: sparql) else { fatalError("Failed to construct SPARQL parser") }
            let query = try p.parseQuery()
            let s = query.serialize()
            count = 1
            print(s)
        } catch let e {
            warn("*** Failed to parse query: \(e)")
        }
    } else if op == "explain" {
        var graph: Term? = nil
        if let next = args.peek(), next == "-g" {
