Fixed putting thread to sleep and while/loop