regroup CTEs into a helper
add query for fetching all logs