Queries refactoring