fixed bug with thread