Changed how the program loops
Moved the opening and closing the logfile to the thread function