Fixed thread sleeping issues