Query code written

Now needs caching