Modified threading to quit on program exit