refactor query graph