logging improved to avoid mixed output