Bugfixes

Fixed a bug with duplicate queries(last 3 commits).