fixed internet connection issues, improved code