cleaned thread code.