improve sleep logic