expanding query building method