final version of all code, now with example queries