Implementing the standard query logic