Refactor and add sparql filtering