added logfile writing