Fixed NULL pointer dereference in tests
Correctly assign thread id