moved query logic out of `findQuery`