fix bug in query string building, add more tests