fix bug with threads