Fix bug with infinite sleeping