fixed/improved query logging