updated buildQuery to more pythonic line length