Bug fix in checking thread ids