refactor across study query