Refactoring query scopes