Fixed bug in query builder