set up query correctly