Bug fixes for smart query feature
More bugfixes for the smart query feature