Fixed issue with sleeping threads