Refactoring query submission