Clenaup THread code