Added log file writing