added query tests; fixed query bug