Added query logging