Do not use the session to get thread IDs (and never without null checking!)
Merge pull request #14 from penguineer/issue-13

Solution for issue #13