Fixed pthread issues