[WIP] Better query creation

I will need to test the url generation before merging.