Take topic of query into account when generating SPARQL queries.
Also, I used some more meaningfull names in go/1, so the algorithm becomes a bit more clear.