fix mutex
fix startup threads number
clean up the code