Added writing to log file