Changed query and data generation