Fixed bug in queries