Bug fix - not using the global query variable