refactoring the query mechanisms out of the main module (towards it
being an API module)