Added flexible parameters to query building