Fixed improperly closing threads.