Refacored add thread code.

Started unit tests for such.