separate query from formatting