Added a thread id generator.

Moved the rest return data into other methods.