Solution for issue #13

Do not use the session to get thread IDs (and never without null checking!)