fixed querying to integrate more tightly with API