Updated query fetching routine