fix threading issue causing segfault