Refactor to DRY out query execution.