finally fixed the treading bug