Fix bug in query string generation