refactor graph queries