Finished first pass at the query lib