built out query logic