improved query logging