fixed query problem, and removed junk code

fixed query problem, and removed junk code.