Fix SPARQL query, make TripleWriter AutoCloseable