Duplication in creating a valid query to send is moved to a method