Add garbage collection for thread pointers, fixes memory leak.
Investigate further for improved performance
Cleanup output of debugging info
Fix bug introduced in commit 979323c6