Implementation of queries