build queries properly