refactor query scope