smarter waiting instead of sleep