refactoring queries