Small fix to the threading code