fixed the thread problem