Re-factoring query submission