Refactoring to avoid segfaults related with pthreads-1.0.4