Can we move this down to where the index query is actually executed? Grouping the query generation and the query execution into 2 separate stages was harder to read for me.