Clean up threaded code