Using a less error-prone sleep function