Added network connection check and crash fix