Small bug fixes for pthreads