code for generating valid queries.