improved sleep implementation