Refactor getting thread id