Fixed bug in looking up thread id for certain contacts