Part 1 of run_query