cleaned up the sleep logic