Optimize wait for internet
Refactoring