Fix memory leak in new thread creation code:

* subthreads were all stored in a thread local
  within the parent thread and not removed automatically
  when thread finished. This resulted in a memory leak
  when a thread continued to spawn new threads.
Tidy up tests