Moved the query execution code into a function.
added functions to list a directory using the gen query API