fix threading issue