Updated query building method to use list