Re-working the query structure for logging