better version with working log file