Simplified query generation code.