Optimize formatting of response for query calls