improved on/offline handling