working version with query logging
working version with query logging