adding offline detection code