Fixed bug with thread working flag