Added debug logging to generic query